我正在尝试使用以下代码将时间戳转换为日期:
String str = "14799744000000800";//last four digit is time zone
DateFormat timeZoneFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
timeZoneFormat.setTimeZone(TimeZone.getTimeZone("GMT-8"));
Date time = new java.util.Date(Long.parseLong(str));
System.out.println(timeZoneFormat.format(time));
但它打印“21-03-470955 00:00:00”而不是 21-03-2016 00:00:00。
如您所见,年份部分未正确转换。如何解决此问题?
最佳答案
当前毫秒值是 1481007881541
,因此 14799744000000800
确实似乎是 future 的值。
编辑 根据您后来的评论,您可以从字符串中删除最后四位数字。
关于java - java中时间戳未正确转换为日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40989467/