Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dealing with dates and Zulu time...

 
Anthony Smith
Ranch Hand
Posts: 285
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting from a source that has no support. In fact, I have no one to ask.
I am assuming this is zulu time related.
This is what the data looks like. These are timestamps...

Timestamp 1: 20040304002300Z-0500
Timestamp 2: 20040505055900Z+0800

I translate Timestmp #1 to mean 03/04/2004 00:23:00
I translate Timestmp #1 to mean 05/05/2004 05:59:00

Would the -0500 subtract 5 hours from my time to make it 03/03/2004 19:23:00
Would the +0800 add 8 hours to my time to make it 13:18:00 ?

If so is there a way that I can I write this in java so that it knows to alter the date if I subtract past 0?
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like UTC encoded time. Here is a class that might help you. 20040304002300Z-0500 would translate into 2004-03-04 (March 4, 2004). Then there is usually a 'T'. 002300Z would be 23 minutes and 0 seconds after midnight. -0500 means 5 hours west of GMT (Greenwich Mean Time). You can probably figure out the other date.
 
Anthony Smith
Ranch Hand
Posts: 285
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You. I did find it. Let me ask you this...

Is there a better(cleaner) way to do this:

SimpleDateFormat fmtTimestamp = new SimpleDateFormat ("yyyyMMddHHmmssZ");

Date dtTimestamp1 = fmtTimestamp.parse(new String("20041221000000Z-0300").replaceAll("Z", ""));

My data includes that Z, which without replacing it would give me a unparseable error:
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The literal Z can be handled with quotes:

No need for the replaceAll() call now. Note too that the call to new String() has been removed, since it never served any purpose at all. It is extremely rare that the new String(String) constructur is really useful for anything; most of the time it just creates another identical String for no reason.
[ January 10, 2005: Message edited by: Jim Yingst ]
 
Anthony Smith
Ranch Hand
Posts: 285
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. My problem is that my data will actually come from a variable.
So how woudl I do it via a variable instead of ever actually seeing the real string.
 
David Harkness
Ranch Hand
Posts: 1646
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anthony Smith:
So how woudl I do it via a variable instead of ever actually seeing the real string.
Simply pass the String variable to the parse() method instead of a String literal.
 
Anthony Smith
Ranch Hand
Posts: 285
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone have a cluse what kind of timestamp this is?

20041020121652170Z

My guess would be
10/20/2004 12:16:52, but where does the 170Z come from?

Here are some other examples:
20050113225010623Z
20050113225010564Z
20050113215545876Z
 
David Harkness
Ranch Hand
Posts: 1646
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anthony Smith:
Does anyone have a cluse what kind of timestamp this is?

20041020121652170Z
My guess would be that the last three digits are milliseconds (thousandths of a second). Java's native handling of time is a long value in milliseconds. SimpleDateFormat can handle this using "S".
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but where does the 170Z come from?

I agree with David that the 170 are most likely milliseconds. For completeness, the Z is for Zulu time - GMT.
[ January 14, 2005: Message edited by: Jim Yingst ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic