In my app, I have a requirement to format 12 hours time to 24 hours time. What is the method I have to use? For example, time like 10:30 AM. How can I convert to 24 hours time in java? Answer Try this: which produces: See: http://download.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html
Tag: time
How to calculate “time ago” in Java?
In Ruby on Rails, there is a feature that allows you to take any Date and print out how “long ago” it was. For example: Is there an easy way to do this in Java? Answer Take a look at the PrettyTime library. It’s quite simple to use: You can also pass in a locale for internationalized message…
How to round time to the nearest quarter hour in java?
Given today’s time e.g. 2:24PM, how do I get it to round to 2:30PM? Similarly if the time was 2:17PM, how do I get it to round to 2:15PM? Answer Rounding You will need to use modulo to truncate the quarter hour: As pointed out by EJP, this is also OK (replacement for the last line, only valid if the
GPS Time Representation library
I am looking for a Java library that handles conversion to/from GPS Time. GPS Time has an epoch of 6 January 1980, and does not have leap seconds, so it differs from the more standard time representations. Here is the relevant description from wikipedia: While most clocks are synchronized to Coordinated Unive…
how to convert minutes to days,hours,minutes
how to convert minutes into days hours and minutes in java ( we have a week here , 7 days ) I tried this but it dont work thanks Answer A shorter way. (Assumes time >= 0)