微信小程序获取当前时间戳、获取当前时间、时间戳加减 2021-
作者:
追逐繁星的阿忠 | 来源:发表于
2021-06-01 22:18 被阅读0次//获取当前时间戳
var timestamp = Date.parse(new Date());
timestamp = timestamp / 1000;
console.log("当前时间戳为:" + timestamp);
//获取当前时间
var n = timestamp * 1000;
var date = new Date(n);
//年
var Y = date.getFullYear();
//月
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
//日
var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
//时
var h = date.getHours();
//分
var m = date.getMinutes();
//秒
var s = date.getSeconds();
console.log("当前时间:" +Y+M+D+h+":"+m+":"+s);
本文标题:微信小程序获取当前时间戳、获取当前时间、时间戳加减 2021-
本文链接:https://www.haomeiwen.com/subject/rtggsltx.html
网友评论