admin 发表于 2014-9-16 17:13:45

js简单的获取当前日期和时间

js简单的获取当前日期和时间


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>js简单的获取当前日期和时间</title>
</head>
<body>
<h1>当期时间</h1>
<a id="times"></a>
<script src="jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
setInterval(showTime,1000);
function timer(obj,txt){
obj.text(txt);
}
/*位数不足补零*/
function checkTime(i){
if (i<10){ i="0" + i } return i }
/*时间和星期获取挤格式*/
function showTime(){
var today = new Date();
var weekday=new Array(7)
weekday="星期一"
weekday="星期二"
weekday="星期三"
weekday="星期四"
weekday="星期五"
weekday="星期六"
weekday="星期日"
var y=today.getFullYear()+"年";
var month=today.getMonth()+"月";
var td=today.getDate()+"日";
var d=weekday+" ";
var h=checkTime(today.getHours())+":";
var m=checkTime(today.getMinutes())+":";
var s=checkTime(today.getSeconds());
timer($("#times"),y+month+td+d+h+m+s);
}})
</script>
</body>
</html>
页: [1]
查看完整版本: js简单的获取当前日期和时间