Unix时间戳记在DateTime中不断返回1970年1月17日 [英] Unix timestamp keeps returning Jan 17 1970 in DateTime

查看:85
本文介绍了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.

http://currentmillis.com/

要从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.

这篇关于Unix时间戳记在DateTime中不断返回1970年1月17日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆