SOURCE

function writeDocument(variable) {
    document.write(variable + "<br/>");
} 

writeDocument("定义时间对象------------");
var oToday = new Date();
writeDocument("获取年,月,日,时,分,秒,毫秒-------------");
writeDocument("年:" + oToday.getFullYear());
writeDocument("月:" + oToday.getMonth());
writeDocument("日:" + oToday.getDate());
writeDocument("时:" + oToday.getHours());
writeDocument("分:" + oToday.getMinutes());
writeDocument("秒:" + oToday.getSeconds());
writeDocument("毫秒:" + oToday.getMilliseconds());

writeDocument("获取年,月,日,时,分,秒,毫秒-------------");
var oData = new Date(2019); 

oData.setFullYear(2020);
writeDocument("年:" + oData.getFullYear());
oData.setMonth(5);
writeDocument("月:" + oData.getMonth());
oData.setDate(1);
writeDocument("日:" + oData.getDate());
oData.setHours(16);
writeDocument("时:" + oData.getHours());
oData.setMinutes(58);
writeDocument("分:" + oData.getMinutes());
oData.setSeconds(59);
writeDocument("秒:" + oData.getSeconds());
oData.setMilliseconds(999);
writeDocument("毫秒:" + oData.getMilliseconds());

var weeks = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
writeDocument("今天是 " + weeks[oToday.getDay()] );

writeDocument("打印2019年6月1日 星期一 15:59:59:99-------------"); 
var oPrintDate = new Date(2019, 6, 1, 15, 59, 59, 99);
writeDocument(oPrintDate.getFullYear() + "年 "
             + oPrintDate.getMonth() + "月 "
             + oPrintDate.getDate() + "日 "
             + weeks[oPrintDate.getDay()] + " "
             + oPrintDate.getHours() + ":" 
             + oPrintDate.getMinutes() + ":"
             + oPrintDate.getSeconds() + ":" 
             + oPrintDate.getMilliseconds());
console 命令行工具 X clear

                    
>
console