给人错误的日期我见过SimpleDateFormat的android系统
Convert from UNIX Timestamp to "Today at: currentTime" using Java
但这些都不是为我工作。
我有一个时间戳:1503037706145
而且我用下面的代码将其转换为一个可读的日期:
Long leadTime = leadData.getLong("addedOn");
Date date = new Date(leadTime*1000);
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy | hh:mm a");
sdf.setTimeZone(TimeZone.getTimeZone("Asia/Calcutta"));
String formattedDate = sdf.format(date);
它返回15/05/49599 11:25:45PM
但是,当我在检查this,它返回Friday, 18 August 2017 07:00:14.817
这是正确的。我究竟做错了什么 ??
FYI,麻烦的老的日期 - 时间类,如['java.util.Date'](https://docs.oracle.com/javase/8/docs/api/java/util/Date .html),['java.util.Calendar'](https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html)和'java.text.SimpleTextFormat'现在[遗留](https://en.wikipedia.org/wiki/Legacy_system),由[java.time]代替(https://docs.oracle.com/javase/8/docs/api/java/time /package-summary.html)类。请参见[Oracle教程](https://docs.oracle.com/javase/tutorial/datetime/TOC.html)。 –
感谢@BasilBourque,我不知道。我会看到教程:) – mrid