http://www.jguru.com/faq/view.jsp?EID=534382
========================================================
Answer
private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss"; /** * @return GMT datetime object as a String */ public String getGmtTime(long eventTime) { TimeZone tz = TimeZone.getTimeZone("GMT:00"); // SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); SimpleDateFormat sdf = new SimpleDateFormat();sdf.applyPattern(DATE_FORMAT); sdf.setTimeZone(tz); Calendar gmtCalendar = Calendar.getInstance(tz); gmtCalendar.setTimeInMillis(eventTime); String stringSDF = sdf.format(gmtCalendar.getTime()); return stringSDF; }========================================================
Answer (deprecated)
Create a custom TimeZone and use it for DateFormat.setTimeZone(). This is discussed briefly in the API documentation and shown in the following code.
========================================================
Answer
You may also want to consider Joda-Time, the alternative to JDK dates – http://joda-time.sourceforge.net Here is how your task would look:
import org.joda.time.*;import org.joda.time.format.*;
public class GMTFmt3
{
public static void main(String[] args)
{
// Get current time using UTC (same as GMT)
DateTime dt = new DateTime(DateTimeZone.UTC);
// output in long format
System.out.println( DateTimeFormat.longDateTime().print(dt) );
}
}