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 oDate = new Date(2019);

oDate.setFullYear(2020);
writeDocument("年:"+oToday.getFullYear());
oDate.setMonth(5);
writeDocument("月:"+oToday.getMonth()+1);
oDate.setDate(1);
writeDocument("日:"+oToday.getDate());

oDate.setHours(5);
writeDocument("时:"+oToday.getHours());
oDate.setMinutes(1);
writeDocument("分:"+oToday.getMinutes());
oDate.setSeconds(59);
writeDocument("秒:"+oToday.getSeconds());
oDate.setMilliseconds(105);
writeDocument("毫秒:"+oToday.getMilliseconds());

var weeks = [,"星期一","星期二","星期三","星期四","星期五","星期六"];
var oPrintDate = new Date(2019,5,1);


writeDocument("---打印2019年6月1日 星期六 15:59:59:51-------------"); 
writeDocument(oPrintDate.getFullYear()+"年"
             +oPrintDate.getMonth()+"月"
             +oPrintDate.getDate()+"日"
             +" "
             +weeks[oPrintDate.getDay()]
             +" "
             +oPrintDate.getHours()+":"
             +oPrintDate.getMinutes()+":"
             +oPrintDate.getSeconds()+":"
             +oPrintDate.getMilliseconds());

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

writeDocument("---————————————分界线————————————---");
writeDocument("---生成随机验证码---");
function generateVerifyCode(length){
    var strValue = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var code = " ";

    for(var i = 0; i < length;++i){
        var randomIndex = Math.floor(Math.random()*strValue.length);
        code += strValue.charAt(randomIndex);
    }
    return code;
}
writeDocument(generateVerifyCode(4));
writeDocument(generateVerifyCode(5));
writeDocument(generateVerifyCode(6));

writeDocument("---用Math发方法找出3,9,12,99,45,78中的最大值和最小值---");
var arr1 = [3,9,12,99,45,78];
var max=Math.max.apply(3,arr1);
var min=Math.min.apply(3,arr1);
writeDocument("最大值是:"+max);
writeDocument("最小值是:"+min);

writeDocument("---请写一个随机生成颜色值rgb(X, Y, Z)的函数,其中X,Y,Z表示的是0~255的数字---"); 
function getRandomColor(){
    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(getRandomColor());
console 命令行工具 X clear

                    
>
console