給人錯誤的日期我見過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