将unix/epoch时间转换为格式化日期 - 意外日期

Dev*_*evC 2 android timestamp android-date

我试图将时间戳转换为人类可读的日期和时间.我试过了:

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);
Run Code Online (Sandbox Code Playgroud)

09-12-2013不过,我得到了预期的结果28-12-45908.上面的例子可以在以下位置找到:将Unix时间戳转换为日期java,由David Hofmann回答

No_*_*ulz 16

试试这个,

public static String Epoch2DateString(long epochSeconds, String formatString) {
    Date updatedate = new Date(epochSeconds * 1000);
    SimpleDateFormat format = new SimpleDateFormat(formatString);
    return format.format(updatedate);
}
Run Code Online (Sandbox Code Playgroud)