我在下面使用代码,得到不同的结果!那我该如何解决呢?
在2.3.5系统中,将于2014年3月20日,星期四03:11:56 GMT + 00:00
在4.x系统中,将于星期四,2014年3月20日格林尼治标准时间
private static final String RFC822_DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss z";
private static DateFormat getRfc822DateFormat() {
SimpleDateFormat rfc822DateFormat = new SimpleDateFormat(RFC822_DATE_FORMAT, Locale.US);
rfc822DateFormat.setTimeZone(new SimpleTimeZone(0, "GMT"));
return rfc822DateFormat;
}
我这样修复它,但是为什么会导致这种情况呢?
public static String formatRfc822Date(Date date)
{
String format = getRfc822DateFormat().format(date);
//fix with android 2.3.5 Thu, 20 Mar 2014 03:11:56 GMT+00:00
if(!format.endsWith("GMT")){
format = format.substring(0, format.lastIndexOf("+"));
}
return format;
}
得到TimeZone
如下...
TimeZone.getTimeZone("GMT+0000")
而不是如下...
new SimpleTimeZone(0, "GMT")
现在,将TimeZone.getTimeZone("GMT+0000")
参数作为参数传递给setTimeZone()
方法,如下所示...
rfc822DateFormat.setTimeZone(TimeZone.getTimeZone("GMT+0000"));
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句