【问题标题】:How to add miliseconds to datetime object如何将毫秒添加到日期时间对象
【发布时间】:2020-02-05 05:48:30
【问题描述】:

我需要将秒转换为HH:mm:ss:ms 格式。我的功能如下。

 function formatTime(time) {
        var rootDate = new Date(new Date(2018, 1, 1, 0, 0, 0).setSeconds(time));
        console.log(rootDate);
        return rootDate;
 }

 formatTime(100);

上述函数给出以下输出,

Thu Feb 01 2018 00:01:40 GMT+0530 (India Standard Time)

你可以看到,它返回时间为00:01:40。但我也需要毫秒部分。比如00:01:40:00我该怎么做。

我需要返回数据时间对象

【问题讨论】:

    标签: javascript jquery datetime milliseconds


    【解决方案1】:

    您是否尝试过类似 setMilliseconds 的函数

    function formatTime(time) {
        var rootDate = new Date(2018, 1, 1, 0, 0, 0);
        rootDate.setMilliseconds(time); 
        console.log(rootDate);
        return rootDate;
    

    }

    格式时间(100);

    【讨论】:

    • 是的,它显示 Thu Feb 01 2018 00:00:00 GMT+0530 (India Standard Time) 作为输出
    猜你喜欢
    • 2023-01-19
    • 1970-01-01
    • 1970-01-01
    • 2016-02-02
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 2019-05-20
    • 1970-01-01
    相关资源
    最近更新 更多