### [小程序怎么获取当前日期](https://www.prosaas.cn/article/16467) **Published:** 2021-01-15T02:04:49 **Author:** 5201314 **Excerpt:** 实现代码:(学习视频分享:编程视频) console.log("当前时间:" + Y + '年' + M+ '… ![](https://img.php.cn/upload/article/202101/15/2021011509511314910.jpg) 实现代码: (学习视频分享:编程视频) 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+ '日' ); 打印结果如下: ![](https://img.php.cn/upload/image/153/138/117/1610676157416953.png) 相关推荐:小程序开发教程 以上就是小程序怎么获取当前日期的详细内容,更多请关注知企PROSAAS其它相关文章! **Categories:** 后端开发 ---