SOURCE

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

//获取时间年月日时分
writeDocument("年:"+oToday.getFullYear());
writeDocument("月:"+(oToday.getMonth()+1));
writeDocument("日:"+oToday.getDate());
writeDocument("时:"+oToday.getHours());
writeDocument("分:"+oToday.getMinutes());

//设置时间
var oMyBrithday=new Date();
oMyBrithday.setFullYear(2019);
oMyBrithday.setMonth(6);
oMyBrithday.setDate(14);
oMyBrithday.setHours(11);
oMyBrithday.setMinutes(30);
oMyBrithday.setSeconds(58,888);
writeDocument(oMyBrithday);

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

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

//打印'今天是2022年3月22日 星期二 8:55 '
/*var myDate=oToday.getDate();
var myMonth=oToday.getMonth()+1;
var myHours=oToday.getHours();
var myMins=oToday.getMinutes();
var myDay=week[oToday.getDay()];
var myYear=oToday.getFullYear();
writeDocument("今天是"+myYear+"年"+myMonth+"月"+myDate+"日"+" "+myDay+" "+myHours+":"+myMins);*/
writeDocument("------------------------时间对象练习----------------------------")
writeDocument("打印2019年6月1日 星期六 15:59:59")
var week=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
var tToday=new Date(2019,6,1,15,59,59);
var myDate=tToday.getDate();
var myMonth=tToday.getMonth();
var myHours=tToday.getHours();
var myMins=tToday.getMinutes();
var myDay=week[6];
var myYear=tToday.getFullYear();
var mySecond=tToday.getSeconds();
writeDocument(myYear+"年"+myMonth+"月"+myDate+"日"+" "+myDay+" "+myHours+":"+myMins+":"+mySecond);
writeDocument("------------------------数学对象练习----------------------------")
//最大值,最小值
writeDocument("最大值:"+Math.max(1,58,26,70,5,90));
writeDocument("最小值:"+Math.min(1,58,26,70,5,90));

//生成随机验证码
function getNum(length){
    var setNum="0123456789ABCDEFGHIJKLMN";
    var code="";
    for(var i=0;i<length;i++){
       var n = Math.floor(Math.random() * setNum.length);
       code=code+setNum.charAt(n);
    }
    return code;
}
writeDocument("验证码:"+getNum(4));
writeDocument("验证码:"+getNum(6));

//生成随机颜色
function getClo(){
    var r=Math.floor(Math.random()*(255+1));
    var g=Math.floor(Math.random()*(255+1));
    var b=Math.floor(Math.random()*(255+1));
    var rgb="rgb("+r+","+g+","+b+")";
    return rgb;
}
writeDocument("随机颜色:"+getClo());
console 命令行工具 X clear

                    
>
console