微信小程序 时间操作

1. 获取当前时间戳

//获取当前时间戳  
var timestamp = Date.parse(new Date());
timestamp = timestamp / 1000;
console.log("当前时间戳为:" + timestamp);

当前时间戳为:1617476114

2. 获取当前时间

//获取当前时间  
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();

console.log("当前时间:" + Y + "年" + M + "月" + D + "日");
var time = Y + "年" + M + "月" + D + "日"

猜你喜欢

转载自blog.csdn.net/zx77588023/article/details/115423896
今日推荐