|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
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[0]="星期一"
- weekday[1]="星期二"
- weekday[2]="星期三"
- weekday[3]="星期四"
- weekday[4]="星期五"
- weekday[5]="星期六"
- weekday[6]="星期日"
- var y=today.getFullYear()+"年";
- var month=today.getMonth()+"月";
- var td=today.getDate()+"日";
- var d=weekday[today.getDay()]+" ";
- 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>
复制代码 |
|