0

js格式化时间戳

 2 years ago
source link: https://blog.p2hp.com/archives/8736
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Lenix Blog

//datetime是拿到的时间戳
var date = new Date(datetime);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
var year = date.getFullYear(),
month = ("0" + (date.getMonth() + 1)).slice(-2),
sdate = ("0" + date.getDate()).slice(-2),
hour = ("0" + date.getHours()).slice(-2),
minute = ("0" + date.getMinutes()).slice(-2),
second = ("0" + date.getSeconds()).slice(-2);
var result = year + "-"+ month +"-"+ sdate +" "+ hour +":"+ minute +":" + second;
return result;

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK