Javascript将秒转换为日期对象 [英] Javascript convert seconds to a date object

查看:135
本文介绍了Javascript将秒转换为日期对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在javascript中将秒数转换为datetime对象。

How can I convert seconds into a datetime object in javascript.

示例:

1.3308313703571

1.3308313703571

1.6324722385401

1.6324722385401

这是从一系列点和发生时。我明白了1.23323多秒,但是我不能改变这个值,从api中拉出来。

This is from a series of points and when they occurred. I understand 1.23323 more then seconds, but I can not change the value, being pulled from an api.

推荐答案

这个:

function toDateTime(secs) {
    var t = new Date(1970, 0, 1); // Epoch
    t.setSeconds(secs);
    return t;
}

纪元日期

这篇关于Javascript将秒转换为日期对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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