js 常用时间日期函数
// js 常用时间日期函数
function load(){
var time = new Date( ); //获得当前时间
var year = time.getFullYear(); //获得年
var month = (time.getMonth()+1); //获得月份 0-11
if(month<10){
month = '0' + month;
}
var ri = time.getDate(); //获得日期 1-31
if(ri<10){
ri = '0' + ri;
}
var hour = time.getHours( ); //获得小时 0-23
var minute = time.getMinutes( ); //获得分钟 0-59
if(minute<10){
minute = "0"+minute;
}
var second = time.getSeconds( ); //获得秒 0-59
if(second<10){
second = "0" + second;
}
//var hm = time.getMilliseconds(); 获得毫秒 0-999
var day = time.getDay(); //获得星期 0-6
document.getElementById("now_time").style.color = '#2A7EB7'; //改变了颜色
switch(day){
case 0:
day = "星期日";
if(day == "星期日"){
document.getElementById("now_time").style.color = '#F00'; //改变了颜色
}
break;
case 1:
day = "星期一";
break;
case 2:
day = "星期二";
break;
case 3:
day = "星期三";
break;
case 4:
day = "星期四";
break;
case 5:
day = "星期五";
break;
case 6:
day = "星期六";
if(day == "星期六"){
document.getElementById("now_time").style.color = '#F00'; //改变style里面颜色的属性
}
break;
}
time =year + "年 "+ month +"月"+ri+"日 "+ hour+":"+minute+":"+second +" "+day;
document.getElementById("now_time").innerHTML = time;
//var time = setTimeout("load()",1000); //setTimeout()小 setInterval()大 看看CUP使用率
}
var time = setInterval("load()",1000);
补充:网页制作,设计基础