//将时间毫秒数转换为指定的时间格式
var format = function(time, format){
var t = new Date(time);
var tf = function(i){return (i < 10 ? '0' : '') + i};
return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a){
switch(a){
case 'yyyy':
return tf(t.getFullYear());
break;
case 'MM':
return tf(t.getMonth() + 1);
break;
case 'mm':
return tf(t.getMinutes());
break;
case 'dd':
return tf(t.getDate());
break;
case 'HH':
return tf(t.getHours());
break;
case 'ss':
return tf(t.getSeconds());
break;
}
})
}
本文介绍了一种使用 JavaScript 将时间毫秒数转换为特定格式的方法。通过定义一个名为 varformat 的函数,可以灵活地将毫秒时间戳转换成年、月、日、时、分、秒等格式。

3357

被折叠的 条评论
为什么被折叠?



