微信小程序获取当前年月日

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38543537/article/details/84454893
var timestamp = Date.parse(new Date());
var date = new Date(timestamp);
//获取年份  
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+ '日' ); 

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

打印结果如下:

猜你喜欢

转载自blog.csdn.net/qq_38543537/article/details/84454893