css中如何显示时间年月日 星期几 几点几分几秒

html-css036

css中如何显示时间年月日 星期几 几点几分几秒,第1张

<html>

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312">

<meta name="keywords" content="js特效" />

<meta name="description" content="js特效网" />

<title>年月日分秒全部显示的时间代码</title>

</head>

<body onload=startclock()>

<form name="clock">

<script language="JavaScript">

var timerID = null

var timerRunning = false

function stopclock (){

if(timerRunning)

clearTimeout(timerID)

timerRunning = false}

function startclock () {

stopclock()

showtime()}

function showtime () {

var now = new Date()

var hours = now.getHours()

var minutes = now.getMinutes()

var seconds = now.getSeconds()

var timeValue = now.getYear()+"年"+(now.getMonth()+1)+"月"+now.getDate()+"日" +((hours >= 12) ? " 下午 " : " 上午 " )

timeValue += ((hours >12) ? hours -12 :hours)

timeValue += ((minutes <10) ? ":0" : ":") + minutes

timeValue += ((seconds <10) ? ":0" : ":") + seconds

document.clock.thetime.value = timeValue

timerID = setTimeout("showtime()",1000)

timerRunning = true}

</script>

<input name="thetime" style="font-size: 9ptcolor:#000000border:1px solid #FFFFFF" size="28"></form>

</body>

</html>

var now = new Date()

var year = now.getFullYear()

var month = now.getMonth()

var day = now.getDate()

var dateValue = year

dateValue += ((month <9) ? "-0" : "-") + (month + 1)

dateValue += ((day <10) ? "-0" : "-") + day

var hours = now.getHours()

var minutes = now.getMinutes()

var seconds = now.getSeconds()

var timeValue = ((hours <10) ? "0" : "") + hours

timeValue += ((minutes <10) ? ":0" : ":") + minutes

timeValue += ((seconds <10) ? ":0" : ":") + seconds

用上面这些JS代码获取你要的时间日期,再将获取到的值显示到你要显示的地方,显示的样式

可以再用CSS控制.

就是隐藏

display:none

当前显示的设置为display:block

一般使用脚本实现

比如你要隐藏的元素为<div id="info1"></div>

要显示的元素为<div id="info2"></div>

假设使用jquery控制

代码为以下两句:

$("#info1").hide()

$("#info2").show()