SOURCE

function writeDocument(variable) {
    document.write(variable + "<br/>");
} 
writeDocument("定义时间对象---------------");
var ot=new Date();
writeDocument(ot);
writeDocument("");

writeDocument("获取年月日时分秒---------------");
writeDocument("年:"+ot.getFullYear());
writeDocument("月:"+(ot.getMonth()+1));
writeDocument("日:"+ot.getDate());
writeDocument("时:"+ot.getHours());
writeDocument("分:"+ot.getMinutes());
writeDocument("秒:"+ot.getSeconds());
writeDocument("");

writeDocument("设置年月日时分秒---------------");
var mb=new Date();
mb.setFullYear(2002);
mb.setMonth(3);
mb.setDate(9);
mb.setHours(3);
mb.setMinutes(9);
mb.setSeconds(30,888);
writeDocument(mb);
writeDocument("");

writeDocument("获取星期几---------------");
writeDocument("星期"+ot.getDay());

var week=["星期天","星期一","星期二","星期三","星期四","星期五","星期六"];
writeDocument(week[ot.getDay()]);

var o=new Date(2022, 3 , 22 , 8 , 55 , 30, 50); 
writeDocument("今天是"+o.getFullYear()+"年"+o.getMonth()+"月"+o.getDate()+"日"+week[o.getDay()]);
console 命令行工具 X clear

                    
>
console