js时间戳、毫秒格式化

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-21 09:36   816   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));
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP