I am trying to calculate the duration between two date objects in minutes. I have found some inspiration during my research from this stackoverflow question. In generally this seems to work correct, …
Tag: datetime
Get last week date range for a date in Java
Suppose I have a Date 20 June 2013 How can I get the Date range for the last week, ie in this case 9 June to 15 June. Also if the date was 2nd June 2013 the range should be 26 may to 1 june Answer this is Java Calendar based solution output it’s localized, in my Locale week starts
Parser Exception for format EEEE, MMMM d, YYYY h:mm:ss a z
I’m getting parser exception on trying to parse string value: To format: This is the program sample: And this is the error message: this is my sample program Answer From the JodaTime docs: Zone names: Time zone names (‘z’) cannot be parsed. However SimpleDateFormat does support parsing of timezones.
Displaying AM and PM in lower case after date formatting
After formatting a datetime, the time displays AM or PM in upper case, but I want it in lower case like am or pm. This is my code: Answer Unfortunately the standard formatting methods don’t let you do that. Nor does Joda. I think you’re going to have to process your formatted date by a simple post-format replace. You could
Removing time from a Date object?
I want to remove time from Date object. But when I’m converting this date (which is in String format) it is appending time also. I don’t want time at all. What I want is simply “21/03/2012”. Answer The quick answer is : No, you are not allowed to do that. Because that is what Date use for. From javadoc of
Unparseable date exception in java
These lines of codes causees this exception what is the possible solution ? Answer Your format is completely wrong. Not only are you using mm (which means minutes) when you probably meant MM, but this: is clearly not in the format You probably want something like EDIT: That works for me in desktop Java: You may want to set the
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 Universal Time (UTC), the atomic clocks on the satellites
Convert Month String to Integer in Java
Given a month string such as: Is there any core Java or third party library functionality that would allow you to convert this string to the corresponding month number in a locale agnostic way? Answer An alternative to SimpleDateFormat using Joda time:
How to get the current date and time
How do I get the current date and time in Java? I am looking for something that is equivalent to DateTime.Now from C#.