【发布时间】:2013-07-17 04:06:46
【问题描述】:
我想要 GMT 时区的当前日期。我使用了以下代码。
public static Date getGMTDate(String dateFormat) throws ParseException
{
SimpleDateFormat dateFormatGmt = new SimpleDateFormat(dateFormat);
dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT"));
// Local time zone
SimpleDateFormat dateFormatLocal = new SimpleDateFormat(dateFormat);
// Time in GMT
return dateFormatLocal.parse(dateFormatGmt.format(new Date()));
}
//调用上面的函数。
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
date = getGMTDate("yyyy-MM-dd HH:mm:ss");
当我将更改我的设备日期时,时间会以 GMT 格式显示,但日期不会以 GMT 时区显示。它会显示设备的日期。 但我想要当前 GMT 日期。
【问题讨论】:
-
另外,我想知道为什么你需要这么多
SimpleDateFormat实例