var date = new Date();
var d = new Date(milliseconds); // 参数为毫秒 参数946656000000 输出 Sat Jan 01 2000 00:00:00 GMT+0800 (GMT+08:00)
var d = new Date(dateString); // 参数 2000-01-02 输出 Sun Jan 02 2000 08:00:00 GMT+0800 (GMT+08:00)
var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);
new Date().getYear(); // 获取当前年份后2位 (已废弃)
new Date().getFullYear(); // 获取完整的年份(4位,1970-至今)
new Date().getMonth(); // 获取当前月份(0-11,0代表1月)
new Date().getDate(); // 获取当前日(1-31)
new Date().getDay(); // 获取当前星期(0-6,0代表星期天)
new Date().getTime(); // 获取当前时间(从1970.1.1 开始的毫秒数)
new Date().getHours(); // 获取当前小时数(0-23)
new Date().getMinutes(); // 获取当前分钟数(0-59)
new Date().getSeconds(); // 获取当前秒数(0-59)
new Date().getMilliseconds(); // 获取当前毫秒数(0-999)
new Date().toLocaleDateString(); // 获取当前日期 (输出结果:2022/2/2)
new Date().toLocaleTimeString(); // 获取当前时间 (输出结果:10:41:30)
new Date().toLocaleString(); // 获取日期与时间 (输出结果:2022/2/2 10:41:30)
(new Date()).Format("Y-m-d H:i:s")
Date.prototype.Format = function (format) {
const year = this.getMonth() + 1;
const month = this.getMonth() + 1;
const day = this.getDate();
const hour = this.getHours();
const minute = this.getMinutes()
const sec = this.getSeconds()
var o = {
"Y": year,
"y": year.substring(year.length-2,year.length),
"m": month>10?month:"0"+month,
"d": day>0?day:"0"+day,
"H": hour>0?hour:"0"+hour,
"h": hour/2>0?hour/2:"0"+hour/2,
"i": minute>0?minute:"0"+minute,
"s": sec>0?sec:"0"+sec,
};
for (var k in o){
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1,o[k]);
}
return fmt;
}