美文网首页
中国标准时间转换成datetime格式

中国标准时间转换成datetime格式

作者: 程序员的自我修养 | 来源:发表于2020-05-26 23:09 被阅读0次

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;

}

});

}

format(result, 'yyyy-MM-dd HH:mm:ss');

相关文章

网友评论

      本文标题:中国标准时间转换成datetime格式

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