时间代码

function clockon(bgclock) {
	var now = new Date();//创建时间
	//本地--->年,月,日,小时,分,秒
		var year = now.getYear();
		var month = now.getMonth();
		var date = now.getDate();
		var day = now.getDay();//0~6-->星期天,一,二,三,四,五,六
		var hour = now.getHours();
		var minu = now.getMinutes();
		var sec = now.getSeconds();
	//本地--->年,月,日,小时,分,秒
	var week;//=============>存放星期的
	month = month + 1;
	if (month < 10)
		month = "0" + month;
	if (date < 10)
		date = "0" + date;
	if (hour < 10)
		hour = "0" + hour;
	if (minu < 10)
		minu = "0" + minu;
	if (sec < 10)
		sec = "0" + sec;
	//----------------星期数组-----------------------
	var arr_week = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
	week = arr_week[day];
	//----------------星期数组-----------------------
	var time = "";
	time = year + "年" + month + "月" + date + "日 " + week + " " + hour + ":"
			+ minu + ":" + sec;
	
		bgclock.innerHTML = time
	
	var timer = setTimeout("clockon(bgclock)", 200);
}

你可能感兴趣的:(代码)