Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

converting a time to GMT and military time format...

807607Sep 20 2006 — edited Jan 8 2007
Hey all

I need to get a time, convert it to GMT, and output it in Military time format.

here is what we have been using.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(startDate.getTime() 
                - calendar.get(Calendar.ZONE_OFFSET));

// startdate is initialized elsewhere
The problem is our times have become an hour off, probably because we changed over to Daylight savings or something and GMT doesnt do that.
The time on the box is correct.

Ive been playing with
calendar.setTimeZone(new SimpleTimeZone(0, "GMT"));
calendar.setTime(new Date());
LOG.info(calendar.getTime());  // output correct GMT time, but not military format
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.FULL,
            DateFormat.DEFAULT);
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
edit: This is not outputting correct GMT time; I thought it was but looked it over and it wasn't.
Anyone know the answer? I dont see anything obvious in the API to do that.

Message was edited by:
shrndegruv
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 5 2007
Added on Sep 20 2006
5 comments
214 views