Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 17:25:17
Original
1067 people have browsed it
复制代码 代码如下:

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;
}
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!