天天看點

js把時間轉換為時間戳

var timer = Date.now();console.log(timer);
var timestamp1 = Date.parse(new Date()); 
var timestamp2 = (new Date()).valueOf();
var timestamp3 = new Date().getTime();
console.log(timestamp1);
console.log(timestamp2);
console.log(timestamp3);
var strtime = '2014-04-23 18:55:49:123';  //把日期轉換為時間戳;
var date = new Date(strtime);
console.log(date);
var date = new Date(1577688324100); //把時間戳轉換為日期
Y = date.getFullYear() + '-';
M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
D = date.getDate() + ' ';
h = date.getHours() + ':';
m = date.getMinutes() + ':';
s = date.getSeconds();
console.log(Y+M+D+h+m+s);

           
js把時間轉換為時間戳

繼續閱讀