This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Problem on great datetime in GMT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem on great datetime in GMT" Watch "Problem on great datetime in GMT" New topic
Author

Problem on great datetime in GMT

HK Stojkovic
Greenhorn

Joined: Dec 19, 2000
Posts: 7
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


HK
kim jungil
Greenhorn

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

Joined: Dec 19, 2000
Posts: 7
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem on great datetime in GMT
 
Similar Threads
Converting from GMT to Local Timezone using two seperate fields (date & time).
Server-Side Includes
GMT
Need Help on Time conversion.
Help:Error with Servlets !!