美文网首页
js时间戳、毫秒格式化

js时间戳、毫秒格式化

作者: 木利 | 来源:发表于2018-07-23 17:36 被阅读0次

function formatDate(now) { 
    var y = now.getFullYear();
    var m = now.getMonth() + 1; // 注意js里的月要加1 
    var d = now.getDate();
    var h = now.getHours(); 
    var m = now.getMinutes(); 
    var s = now.getSeconds();

    return y + "-" + m + "-" + d + " " + h + ":" + m + ":" + s; 
} 

var nowDate = new Date(2016, 5, 13, 19, 18, 30, 20);

console.log(nowDate.getTime()); // 获得当前毫秒数: 1465816710020
console.log(formatDate(nowDate));

相关文章

网友评论

      本文标题:js时间戳、毫秒格式化

      本文链接:https://www.haomeiwen.com/subject/cwijmftx.html