一、获取当前时间戳
var timestamp = new Date().getTime();console.log(timestamp);
二、yyyy-MM-dd hh:mm:ss 格式的当前时间
function getdate() { var now = new Date(); var Y = now.getFullYear(); var M = now.getMonth() + 1; var D = now.getDate(); var m = M < 10 ? "0" + M : M; var d = D < 10 ? "0" + D : D; return Y + "-" + m + "-" + d + " " + now.toTimeString().substr(0, 8); }
三、时间转为时间戳
function gettime(dateTime) { var time = Date.parse(new Date(dateTime)); return time; }
var stringTime = ‘2017/06/13 10:22:00‘;
console.log(stringTime + "的时间戳为:" + gettime(stringTime))
时间: 2024-10-23 08:43:12