File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes GMT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "GMT" Watch "GMT" New topic
Author

GMT

Kjartan Reynisson
Greenhorn

Joined: Mar 31, 2006
Posts: 4
I need to create GregorianCalendar GMT time, but the below code retunrs my timezone CEST.


Can anyone show me how to get GTM?
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780

Here's the scoop: Calendar's getTime method returns a Date object:

Date getTime() //not the best method name, eh?

... and Date's state don't include a time zone. Its toString method implicitly uses your JVM's default time zone! WTF?!

To get around this, use a DateFormat, but don't forget to set it's TimeZone property first!

You can also avoid Calendar and go directly with Date if you just want the current date:

DateFormat df = DateFormat.getDateTimeInstance();
df.setTimeZone(TimeZone.getTimeZone("GMT"));
Date date = new Date();
System.out.println("now = " + date);
System.out.println("now in GMT = " + df.format(date));
[ April 03, 2006: Message edited by: Jeff Albertson ]

There is no emoticon for what I am feeling!
 
Don't get me started about those stupid light bulbs.
 
subject: GMT
 
Similar Threads
Daylight saving problem
settimezone on gregorian calendar doesn't work !!
Problem on great datetime in GMT
calendar timezone
Question about using a specific TimeZone to set a GregorianCalendar...