您的位置:首页 > Web前端 > JavaScript

js时间转化为指定格式时间

2015-09-07 19:25 555 查看
////将中国标准时间转化为指定格式时间 
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;
}
})
};


为了解决java 后台程序传过来的时间与js当前时间格式不一致的问题,使用eval("new Date("+ now Date().replace(/\D+/g,",")+")") 将时间转化为一致的时间格式
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: