SOURCE

document.write("定义时间对象");
var oToday=new Date();

document.write("获取年月日时分秒");
document.write("nian:"+oToday.getFullYear());
document.write("yue:"+oToday.getMonth());
document.write("ri:"+oToday.getDate());
document.write("shi:"+oToday.getHours());
document.write("fen:"+oToday.getSeconds());
document.write("miao:"+oToday.getMinutes());
document.write("haomiao:"+oToday.getMilliseconds());

document.write("设置年月日时分秒<br/>");
var oDate=new Date(2019);
oDate.setFullYear(2022);
document.write("nian:"+oDate.getFullYear()+"<br/>");
oDate.setMonth(11);
document.write("yue:"+oDate.getMonth()+"<br/>");
oDate.setDate(2);
document.write("ri:"+oDate.getDate()+"<br/>");
oDate.setHours(20);
document.write("shi:"+oDate.getHours()+"<br/>");
oDate.setSeconds(40);
document.write("fen:"+oDate.getSeconds()+"<br/>");
oDate.setMinutes(21);
document.write("miao:"+oDate.getMinutes()+"<br/>");
oDate.setMilliseconds(46);
document.write("haomiao:"+oDate.getMilliseconds()+"<br/>");

var weeks=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
document.write("今天是:"+weeks[oToday.getDay()]+"<br/>");
var oPrintDate=new Date(2022,4,5,12,43,111,845);
//同上

console 命令行工具 X clear

                    
>
console