This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to compare the datetime to find the latest datatime Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "How to compare the datetime to find the latest datatime" Watch "How to compare the datetime to find the latest datatime" New topic
Author

How to compare the datetime to find the latest datatime

Mike Boota
Ranch Hand

Joined: Jul 18, 2002
Posts: 82
Hi,

I have an xml payload with multiple fields for date-time. The datetime is populated as below:

2007-04-06T10:46:47.411-05:04
2007-04-06T10:46:47.410+02:01
2007-04-06T10:46:47.411-03:00
2007-04-06T10:46:47.411+09:03
2007-04-06T10:46:47.411-09:03

Now how do I find out which is the latest datetime. Any help is appreciated.

Thanks


MB<br />Sun Certified Programmer for Java2 Platform
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
Well, those look like ISO 8601 formats. You should be able to parse them easily with a SimpleDateFormat. The Java Tutorial is a good place to learn how this works.

EXCEPT...

The last part of those times makes no sense. For example "-05:04" indicates that the time was recorded in a time zone whose offset was 5 hours and four minutes behind Greenwich Mean Time. The fact that all but one of the time zone offsets are nonzero is deeply suspicious. In the real world, time zone offsets mostly have the minutes set to 0. Some have 30 or 45. Here's a list. But the fact that the numbers shown here are 4, 1, 3... that makes me think that whoever recorded these times did not do so correctly.

Perhaps someone made up some numbers as examples of the format, without fully understanding them? That's fine. But if this is supposed to be "real" data, I think it's highly probable that it's defective, and this can probably only be fixed by understanding how the times were recorded in the first place, and what format did they think they were using.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to compare the datetime to find the latest datatime
 
Similar Threads
UnsupportedClassVersionError, Can the good people help
I have some problems
Hibernated Pojo Generator using config.xml for Oracle database
Retriving data from a log file
A SimpleDateFormat for ISO 8601