0
我試圖將時間戳轉換爲人類可讀的日期和時間。我想:將unix/epoch時間轉換爲格式化日期 - 意外日期
String dateSt = 1386580621268;
Log.i("*****", "date st is = "+dateSt);
long unixSeconds = Long.parseLong(dateSt);
Log.i("*******", "unix seconds is = "+unixSeconds);
Date date = new Date(unixSeconds*1000L); // *1000 is to convert seconds to milliseconds
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); // the format of your date
String formattedDate = sdf.format(date);
System.out.println(formattedDate);
預期的結果是要09-12-2013
,但是我得到28-12-45908
。上面的例子可以發現於:Convert Unix timestamp to date java, answer by David Hofmann
啊我看到了,非常感謝你清除那個。它現在正常工作:)我剛剛刪除了像你所建議的'* 1000L'。再次感謝。 – DevC