File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem on great datetime in GMT

 
HK Stojkovic
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could anyone tell me how to create a datetime in GMT
Followings are my codes,
---------------------------------------------------
TimeZone tz = TimeZone.getTimeZone("GMT");
GregorianCalendar today = new GregorianCalendar(tz);
currenttime = today.getTime();

SimpleDateFormat DF = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
String strCurrenttime = DF.format(currenttime);
System.out.println(strCurrenttime);
------------------------------------------------
I use a SimpleDateFormat to get date string but the output datetime is in my country time zone(not GMT)
Thanks
ST
 
kim jungil
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by HK Stojkovic:
Could anyone tell me how to create a datetime in GMT
Followings are my codes,

TimeZone represents a time zone offset, and also figures out daylight savings.
Typically, you get a TimeZone using getDefault which creates a TimeZone based on the time zone where the program is running. For example, for a program running in Japan, getDefault creates a TimeZone object based on Japanese Standard Time.
You can also get a TimeZone using getTimeZone along with a time zone ID. For instance, the time zone ID for the U.S. Pacific Time zone is "America/Los_Angeles". So, you can get a U.S. Pacific Time TimeZone object with:
TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");

You can use getAvailableIDs method to iterate through all the supported time zone IDs. You can then choose a supported ID to get a TimeZone. If the time zone you want is not represented by one of the supported IDs, then you can create a custom time zone ID with the following syntax:
GMT[+|-]hh[[:]mm]

For example, you might specify GMT+14:00 as a custom time zone ID. The TimeZone that is returned when you specify a custom time zone ID does not include daylight savings time.
For compatibility with JDK 1.1.x, some other three-letter time zone IDs (such as "PST", "CTT", "AST") are also supported. However, their use is deprecated because the same abbreviation is often used for multiple time zones (for example, "CST" could be U.S. "Central Standard Time" and "China Standard Time"), and the Java platform can then only recognize one of them.

 
HK Stojkovic
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to create a timeZone by the ID 'GMT' and 'JST' But I still get a datetime in 'CST' (my default timezone id). So any more suggestions?
Thanks
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic