我试图将时间戳转换为人类可读的日期和时间。我试过了:
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
。上面的示例可以在以下位置找到:将 Unix 时间戳转换为日期 java,David Hofmann 的回答