js格式化时间

转自:https://blog.csdn.net/u010964869/article/details/51095827

显示格式为:yyyy-mm-dd hh:mi:ss


function formattime(val){

    if(val == "" || val == null || val == undefined){
return "";
}
var date = new Date(val);
var year = parseInt(date.getFullYear());
var month = (parseInt(date.getMonth())+1);
var day = parseInt(date.getDate());
day = day > 9 ? day:('0'+day);
var hours = parseInt(date.getHours());
hours = hours > 9 ? hours:('0'+hours);
var minutes = parseInt(date.getMinutes());
minutes = minutes > 9 ? minutes:('0'+minutes);
var seconds = parseInt(date.getSeconds());
seconds = seconds > 9 ? seconds:('0'+seconds);
var time = year+'-'+month+'-'+day+' '+hours+':'+minutes+':'+seconds; return time;
}
 

注:parseInt可以不要

上一篇:【转】傅里叶变换 拉普拉斯变 z变换 DFT DCT意义


下一篇:[SHOI2007]善意的投票