KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have two timestamps which describe the same instant of time in two different formats. 2010-10-03 18:58:07 and 2010-10-03T16:58:07.000+02:00 . I parse the timestamps with two different date formatters with Joda-Time. In the end I want to have two DateTime objects that are equal in terms of being the same instant of time. The DateFormatter offers several methods to control time zones and locales but i couldn't get it to work. This is the code that i would like to work: final String date1 = "2010-10-03 18:58:07"; // Europe/Berlin local time final DateTimeFormatter formatter1 = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); final DateTime dateTime1 = formatter1.parseDateTime(date1); final String date2 = "2010-10-03T16:58:07.000+02:00"; // Europe/Berlin local time with time zone final DateTimeFormatter formatter2 = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); final DateTime dateTime2 = formatter2.parseDateTime(date2); Assert.assertTrue(dateTime1.isEqual(dateTime2));
Tags (comma-separated)
Save Edits
Cancel