Unix时间戳记在DateTime中不断返回1970年1月17日
我正在使用以下方法返回格式化的日期,例如07:00AM, Apr 12 2016
.但是我一直得到01:41PM, Sat, Jan 17 1970
.假设我的时间戳是1460469600
.
I am using the following method to return a formatted date as say 07:00AM, Apr 12 2016
. But I keep getting 01:41PM, Sat, Jan 17 1970
. Say for example my timestamp is 1460469600
.
这是我的方法.
public static String formattedDate(long timestamp) {
DateTime date = new DateTime(timestamp);
String formatted= date.toString("hh:mma, EEE, MMM dd yyyy");
return formatted;
}
您的时间戳错误.它不代表正确的时间(以毫秒为单位). Y我们的时间戳记是1970年1月17日(星期六)下午01:41.
Your timeStamp is wrong. It doesnt represent the correct time in millis. YOur timeStamp refers to 01:41PM, Sat, Jan 17 1970.
您可以从此站点检查timeinmillis(TimeStamp)指的是什么日期.
You can check what time date the timeinmillis (TimeStamp) refers to from this site.
要从Unix时间戳获取正确的时间,只需更改DateTime date = new DateTime(timestamp);进入
To get the correct time from unix time stamp just change your DateTime date = new DateTime(timestamp); into
DateTime date = new DateTime(timestamp*1000);
因为unix时间以秒为单位显示timpestamp,所以我们在这里需要毫秒.
Because unix time gives timpestamp in seconds and we need millis here.