SOURCE

//定义一个时间对象
var ttime = new Date();
document.write("获取年月日,时分秒"+"</br>");
document.write("年"+ttime.getFullYear()+"</br>");
document.write("月"+ttime.getMonth()+"</br>");
document.write("日"+ttime.getDate()+"</br>");
document.write("时"+ttime.getHours()+"</br>");
document.write("分"+ttime.getMinutes()+"</br>");
document.write("秒"+ttime.getSeconds()+"</br>");
document.write("毫秒"+ttime.getMilliseconds()+"</br>");
//设置
var time = new Date(2019);
document.write("时间"+time.getDay()+"</br>");
document.write("时间"+time.getFullYear()+"</br>");
time.setFullYear(2020);
document.write("年"+time.getFullYear()+"</br>");
time.setMonth(1);
document.write("月"+time.getMonth()+"</br>");
time.setDate(19);
document.write("日"+time.getDate()+"</br>");
time.setHours(1);
document.write("时"+time.getHours()+"</br>");
time.setMinutes(19);
document.write("分"+time.getMinutes()+"</br>");
time.setSeconds(1);
document.write("秒"+time.getSeconds()+"</br>");
time.setMilliseconds(19);
document.write("毫秒"+time.getMilliseconds()+"</br>");
//数组星期
var  weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]; 
//打印
var oPrintDate = new Date(2019, 5, 1, 15, 59, 59, 999); 
document.write("打印2019年6月1日 星期六 15:59:59:999-------------"+"</br>"); 
document.write(oPrintDate.getFullYear()+"年"+(oPrintDate.getMonth()+1)+"月"
+oPrintDate.getDate()+"日"+" "+weeks[oPrintDate.getDay()]+" "+oPrintDate.getHours()+":"
+oPrintDate.getMinutes()+":"+oPrintDate.getSeconds()+":"+oPrintDate.getMilliseconds()+"</br>");
console 命令行工具 X clear

                    
>
console