function gettime() {
// 创建一个 Date 对象
var today = new Date();
// 获取年、月、日、时、分、秒
var year = today.getFullYear();
var month = today.getMonth() + 1; // 月份是从 0 开始计数的,需要加1
var day = today.getDate();
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
// 格式化输出
return year + "-" +
(month < 10 ? "0" : "") + month + "-" +
(day < 10 ? "0" : "") + day
}```
标签:MM,dd,month,yyyy,Date,year,var,day,today
From: https://blog.csdn.net/shanshanbao/article/details/144235747