欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

js日期格式转换

程序员文章站 2022-04-03 22:19:12
...

//日期毫秒值转换成固定格式

function dateFmt(val){
var date = new Date(val);
Y = date.getFullYear() + '-';
M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
D = date.getDate()>9 ? date.getDate()+' ' : '0'+date.getDate()+' ';
h = date.getHours()>9? date.getHours() + ':' : '0'+date.getHours()+":";
m = date.getMinutes()>9? date.getMinutes() + ':' : '0' + date.getMinutes()+':';
s = date.getSeconds()>9? date.getSeconds() : '0'+date.getSeconds();
return Y+M+D+h+m+s;

}

相关标签: javascript