美文网首页
Unix 时间戳转 UTC 时间

Unix 时间戳转 UTC 时间

作者: 数据小白鼠 | 来源:发表于2018-12-05 15:06 被阅读0次

说明

在最近的项目中,时间数据是以秒的形式展现的,需要将时间转换成 UTC + 0800 的形式,才有了如下代码。

代码实现

public class TestTime {

    public static void main(String[] args) {
        /*Date date = new Date();
        date.setTime(1543904896 * 1000L);
        System.out.println(date.getYear());*/


        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(1543904896L * 1000L);//转换为毫秒
        Date date = calendar.getTime();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");
        System.out.print(format.format(date));

    }

}

相关文章

网友评论

      本文标题:Unix 时间戳转 UTC 时间

      本文链接:https://www.haomeiwen.com/subject/jhfwcqtx.html