Java UTC时间戳未返回正确的时间
我在Java UTC时间戳未返回正确的时间,java,android,simpledateformat,date-formatting,Java,Android,Simpledateformat,Date Formatting,我在EST中从服务器获得一个日期字符串,因此我将其转换 示例日期2013-04-16T11:56:07.15 incidentDate = l.item(0).getTextContent(); DateFormat dformat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS",Locale.US); dformat.setTimeZone(TimeZone.getTime
EST
中从服务器获得一个日期字符串,因此我将其转换
示例日期2013-04-16T11:56:07.15
incidentDate = l.item(0).getTextContent();
DateFormat dformat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS",Locale.US);
dformat.setTimeZone(TimeZone.getTimeZone("America/New York"));
Date timestamp;
try
{
timestamp = dformat.parse(incidentDate);
incidentDateLong = timestamp.getTime();
}
catch (ParseException e1) {
e1.printStackTrace();
}
返回的时间戳是136611367015
如果我把它插入这个网站上的转换器来检查日期
毫秒似乎不是正确的日期,它给我提供了2013年4月16日星期二07:56:07 GMT-0400(东部夏令时)
这不是从服务器发送给我的
当我将日期转换回原来的日期时,它会将日期拉回到离实际日期更远的地方
Date incDate = new Date(dateInMili);
DateFormat dformat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a",Locale.US);
String dateStr = dformat.format(incDate);
我的格式化程序有问题吗?我不明白问题所在这就是问题所在:
TimeZone.getTimeZone("America/New York")
这不是有效的时区ID。您需要:
TimeZone.getTimeZone("America/New_York")
请注意下划线。就我个人而言,
getTimeZone
没有显示它实际上没有找到你要求的时区,这是一件很遗憾的事,但这种情况已经持续了很长时间:(你应该检查一下。哇,我只是花了4个小时试图弄明白这一点,而它只是一个愚蠢的下划线……真是浪费时间。谢谢!!