【发布时间】:2013-05-28 15:51:03
【问题描述】:
我编写了以下代码以从 unix 时间戳获取 GMT 日期
private Date converToDate(String unixTimeStamp)
{
//unix timestamps have GMT time zone.
DateFormat gmtFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
gmtFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
//date obtained here is in IST on my system which needs to be converted into GMT.
Date time = new Date(Long.valueOf(unixTimeStamp) * 1000);
String result = gmtFormat.format(time);
return lineToDate(result, true);
}
这段代码在执行时有
Mon May 27 02:57:32 IST 2013
日期变量中的值和
Sun May 26 21:27:32 GMT 2013
在结果变量中,如何直接将结果变量中的值放入日期变量中?
【问题讨论】:
-
在字符串中给出结果,我在字符串中得到它,但我想要的是结果应该是日期而不是字符串。
-
查看上述问题中的回复stackoverflow.com/a/2453820/2235132。
标签: java date simpledateformat gmt