Javascript 如何向datetime对象添加毫秒
我需要将秒转换为Javascript 如何向datetime对象添加毫秒,javascript,jquery,datetime,milliseconds,Javascript,Jquery,Datetime,Milliseconds,我需要将秒转换为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:0
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
我该怎么做
我需要返回datatime对象您是否尝试过类似的setMillimes函数
function formatTime(time) {
var rootDate = new Date(2018, 1, 1, 0, 0, 0);
rootDate.setMilliseconds(time);
console.log(rootDate);
return rootDate;
}
形成时间(100) 是的,它的输出显示为2018年2月1日星期四00:00:00 GMT+0530(印度标准时间)