您的位置:首页 > Web前端 > JavaScript

js时间戳、毫秒格式化

2017-06-28 18:24 232 查看
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));
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: