标签:
function formats(time, format){
/*time:2016-10-17*/
/*format:yyyy-MM-dd HH:mm:ss*/
var times = parseInt((new Date(time.replace(new RegExp("-","gm"),"/"))).getTime()) + parseInt(90 * 24 * 60 * 60 * 1000);
var t = new Date(times);
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 ‘dd‘:
return tf(t.getDate());
break;
case ‘HH‘:
return tf(t.getHours());
break;
case ‘mm‘:
return tf(t.getMinutes());
break;
case ‘ss‘:
return tf(t.getSeconds());
break;
}
})
}
标签:
原文地址:http://www.cnblogs.com/myclovers/p/5970847.html