function writeDocument(variable) {
document.write(variable + "<br/>");
}
writeDocument("定义一个时间对象-----------------------------------------------");
var oToday=new Date();
writeDocument(oToday);
writeDocument("获取时间对象:年、月、日、时、分、秒----------------------------------------------");
writeDocument("年:"+oToday.getFullYear());
writeDocument("月:"+(+oToday.getMonth()+1));
writeDocument("日:"+oToday.getDate());
writeDocument("时:"+oToday.getHours());
writeDocument("分:"+oToday.getMinutes());
writeDocument("秒:"+oToday.getSeconds());
writeDocument("设置时间对象:年、月、日、时、分、秒(2001-12-13 11:30:58.888)----------------------------------------------");
var oMybirthday=new Date();
oMybirthday.setFullYear(2001);
oMybirthday.setMonth(12);
oMybirthday.setDate(13);
oMybirthday.setHours(11);
oMybirthday.setMinutes(30);
oMybirthday.setSeconds(58,888);
writeDocument(oMybirthday);
writeDocument("获取星期几-----------------------------------------------");
writeDocument("今天是星期"+oToday.getDay());
var week=["星期天","星期一","星期二","星期三","星期四","星期五","星期六"];
writeDocument("今天是"+week[oToday.getDay()]);
writeDocument("设置时间对象的年月日时分秒,打印2019年6月1日 星期六 15:59:59:99)----------------------------------------------");
var oThistime=new Date();
oThistime.setFullYear(2019,6,1);
oThistime.setHours(15, 59, 59, 99);
writeDocument(oThistime);
function writeDocument(variable) {
document.write(variable + "<br/>");
}
writeDocument("最大值,最小值-----------------------------------------------");
writeDocument("最大值:"+Math.max(1,3,9,10,18,999));
writeDocument("最小值:"+Math.min(1,3,9,10,18,999));
writeDocument("生成4位数随机验证码-----------------------------------------------");
function generateVerifyCode(length){
var strLetterNumber="0123456789ABCDEFGHIJKLMNOPQRST";
var code="";
for(var i=0;i<length;++i){
var randomNumber=Math.floor(Math.random()*strLetterNumber.length);
code=code+strLetterNumber.charAt(randomNumber);
}
return code;
}
writeDocument(generateVerifyCode(4));
writeDocument(generateVerifyCode(5));
writeDocument(generateVerifyCode(6));
writeDocument("生成随机颜色 rgb(255,255,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;
}
document.write(getRandomColor());
console