aspose file tools*
The moose likes Beginning Java and the fly likes Dealing with dates and Zulu time... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Dealing with dates and Zulu time..." Watch "Dealing with dates and Zulu time..." New topic
Author

Dealing with dates and Zulu time...

Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
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

Joined: Jul 22, 2000
Posts: 9046
    
  10
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.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
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

Joined: Jan 30, 2000
Posts: 18671
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 ]

"I'm not back." - Bill Harding, Twister
Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
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

Joined: Aug 07, 2003
Posts: 1646
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

Joined: Sep 10, 2001
Posts: 285
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

Joined: Aug 07, 2003
Posts: 1646
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

Joined: Jan 30, 2000
Posts: 18671
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
 
subject: Dealing with dates and Zulu time...