Home  >  Article  >  Web Front-end  >  JS function to convert timestamp to time year, month, day and time_javascript skills

JS function to convert timestamp to time year, month, day and time_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:25:171096browse
复制代码 代码如下:

ormatDate:function(dateNum){
var date=new Date(dateNum*1000);
return date.getFullYear() "-" fixZero(date.getMonth() 1,2) "-" fixZero(date.getDate(),2) " " fixZero(date.getHours(),2) ":" fixZero(date.getMinutes(),2) ":" fixZero(date.getSeconds(),2);
function fixZero(num,length){
var str="" num;
var len=str.length;
var s="";
for(var i=length;i-->len;){
s ="0";
}
return s str;
}
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn