SOURCE

//var 日期对象名 = new date()
//getFullYear 年
//getMonth()  月
//getDate()  日
//setYear(year,month,day)
function writeDocument(variable) {
    document.write(variable + "<br/>");
} 
writeDocument("定义时间对象---------------------");
var oToday = new Date();
writeDocument(oToday + "<br/>");

writeDocument("获取年,月,日,时,分,秒---------------------");
writeDocument("年:"+oToday.getFullYear());
writeDocument("月:"+oToday.getMonth()+1);
writeDocument("日:"+oToday.getDate());
writeDocument("时:"+oToday.getHours());
writeDocument("分:"+oToday.getMinutes());
writeDocument("秒:"+oToday.getSeconds() + "<br/>");

writeDocument("设置年,月,日,时,分,秒,毫秒---------------------");
var oDate = new Date(2019);

oDate.setFullYear(2020);
writeDocument("年:"+oDate.getFullYear());
oDate.setMonth(5);
writeDocument("月:"+(oDate.getMonth()+1));
oDate.setDate(1);
writeDocument("日:"+(oDate.getMonth()));
oDate.setHours(11);
writeDocument("时:"+(oDate.getHours()));
oDate.setMinutes(30);
writeDocument("分:"+(oDate.getMinutes()));
oDate.setSeconds(58,888);
writeDocument("秒:"+(oDate.getSeconds()));
oDate.setMilliseconds(999);
writeDocument("毫秒:"+(oDate.getMilliseconds()));
writeDocument("<br/>");


writeDocument("获取星期几------------");
//writeDocument("今天是星期"+oToday.getDay());

//星期天是0
var week= ["星期天","星期一","星期二","星期三","星期四","星期五","星期六"];

writeDocument("今天是"+week[oToday.getDay()]);
writeDocument("<br/>");


writeDocument("请你打印:今天是2022年3月22日 星期二 8:55  ----------------"); 
//new Date(year, monthIndex [, day [, hours [, minutes [, seconds [, milliseconds]]]]]); 

var oDate=new Date(2022,3,22,8,55)
var Year = oDate.getFullYear();
var month = oDate.getMonth();
var Date = oDate.getDate();

var Today = week[oToday.getDay()];
var Hour = oDate.getHours();
var Minutes = oDate.getMinutes();

writeDocument("今天是"+Year+"年"+month+"月"+Date+"日"+" "+Today+Hour+":"+Minutes);












console 命令行工具 X clear

                    
>
console