我写了下面的代码从unix时间戳获得GMT日期获得在GMT日期从Unix时间戳
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
在结果变量,我如何直接获取结果变量的值到日期变量可以吗?
这给出了字符串中的结果,我米字符串获取它,但我想要的是,结果应该是一个日期不是字符串。 –
请参阅上面问题中的回复http://stackoverflow.com/a/2453820/2235132。 – devnull