【发布时间】:2013-09-26 14:50:46
【问题描述】:
我在显示日期时遇到问题,我得到的时间戳为 1379487711,但据此实际时间是 2013 年 9 月 18 日下午 12:31:51,但它显示的时间为 1970 年 17 月 41 日。如何显示为当前时间。
为了显示时间,我使用了以下方法:
private String getDate(long milliSeconds) {
// Create a DateFormatter object for displaying date in specified
// format.
SimpleDateFormat formatter = new SimpleDateFormat("dd-mm-yyyy");
// Create a calendar object that will convert the date and time value in
// milliseconds to date.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis((int) milliSeconds);
return formatter.format(calendar.getTime());
}
【问题讨论】:
-
你确定这是毫秒而不是简单的秒吗?用它来检查你的时间:onlineconversion.com/unix_time.htm
-
当我检查答案是星期三,2013 年 9 月 18 日 07:01:51 UTC
-
我使用时间戳很长时间 = System.currentMilliSeconds;
-
如果你愿意,你可以试试这个,对我来说效果很好。 Firebase Functions
标签: java android date timestamp