new Date() 获取当前时间,如格式为 年-月-日,可以使用如下方法:
const date = new Date();
const current_date = date.getDate();
// 获取本 日
const current_month = date.getMonth() + 1;
// 获取本 月
const current_year = date.getFullYear();
// 获取本 年
console.log('-----------------------------------------------------');
console.log(current_year + '-' + current_month + '-' + current_date);
console.log('-----------------------------------------------------');
打印后:

JS日期操作
本文介绍如何使用JavaScript中的newDate()函数来获取并格式化当前日期,包括获取年、月、日等基本信息。
6307

被折叠的 条评论
为什么被折叠?



