用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - javascript代码库

js 显示详细日期时间

2012-09-16 作者: 小蜜锋举报

[javascript]代码库

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>js 显示详细日期时间</title>
</head>
<body>
<SCRIPT language=Javascript>
	var tags_before_clock = "<font face='geneva, arial, helvetica, sans-seif' size='4' color='#0000FF'>现在时间:"
	var tags_middle_clock = "on"
	var tags_after_clock = "</font>"

	if (navigator.appName == "Netscape") {
		document.write('<layer id="clock"></layer><br>');
	}

	if (navigator.appVersion.indexOf("MSIE") != -1) {
		document.write('<span id="clock"></span>');
	}

	DaysofWeek = new Array()
	DaysofWeek[0] = "Sunday"
	DaysofWeek[1] = "Monday"
	DaysofWeek[2] = "Tuesday"
	DaysofWeek[3] = "Wednesday"
	DaysofWeek[4] = "Thursday"
	DaysofWeek[5] = "Friday"
	DaysofWeek[6] = "Saturday"

	Months = new Array()
	Months[0] = "January"
	Months[1] = "February"
	Months[2] = "March"
	Months[3] = "April"
	Months[4] = "May"
	Months[5] = "June"
	Months[6] = "July"
	Months[7] = "August"
	Months[8] = "September"
	Months[9] = "October"
	Months[10] = "November"
	Months[11] = "December"

	function upclock() {
		var dte = new Date();
		var hrs = dte.getHours();
		var min = dte.getMinutes();
		var sec = dte.getSeconds();
		var day = DaysofWeek[dte.getDay()]
		var date = dte.getDate()
		var month = Months[dte.getMonth()]
		var year = dte.getFullYear()

		var col = ":";
		var spc = " ";
		var com = ",";
		var apm;

		if (date == 1 || date == 21 || date == 31) {
			ender = "<sup>st</sup>"
		} else if (date == 2 || date == 22) {
			ender = "<sup>nd</sup>"
		} else if (date == 3 || date == 23) {
			ender = "<sup>rd</sup>"
		}

		else {
			ender = "<sup>th</sup>"
		}

		if (12 < hrs) {
			apm = "<font size='-1'>pm</font>";
			hrs -= 12;
		}

		else {
			apm = "<font size='-1'>am</font>";
		}

		if (hrs == 0)
			hrs = 12;
		if (hrs <= 9)
			hrs = "0" + hrs;
		if (min <= 9)
			min = "0" + min;
		if (sec <= 9)
			sec = "0" + sec;

		if (navigator.appName == "Netscape") {
			document.clock.document.write(tags_before_clock + hrs + col + min
					+ col + sec + apm + spc + tags_middle_clock + spc + day
					+ com + spc + date + ender + spc + month + com + spc + year
					+ tags_after_clock);
			document.clock.document.close();
		}

		if (navigator.appVersion.indexOf("MSIE") != -1) {
			clock.innerHTML = tags_before_clock + hrs + col + min + col + sec
					+ apm + spc + tags_middle_clock + spc + day + com + spc
					+ date + ender + spc + month + com + spc + year
					+ tags_after_clock;
		}
	}

	setInterval("upclock()", 1000);
</SCRIPT>
</body>
</html>

[代码运行效果截图]


js 显示详细日期时间


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...