jquery 获取当前时间

方法一:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
    <script type="text/javascript" src="/jquery.min.js"></script>  
</head>
<body>
<script type="text/javascript">
function current(){
var d=new Date(),str='';
str +=d.getFullYear()+'年'; //获取当前年份
str +=d.getMonth()+1+'月'; //获取当前月份(0——11)
str +=d.getDate()+'日';
str +=d.getHours()+'时';
str +=d.getMinutes()+'分';
str +=d.getSeconds()+'秒';
return str; }
setInterval(function(){$("#nowTime").html(current())},1000);
</script>
<div id="nowTime"></div>
</body>

</html>


方法二:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  2. <html>  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  5. <title>jquery 动态显示时间</title>  
  6. <script type="text/javascript" src="js/jquery-1.7.2.js"></script>  
  7. <script type="text/javascript">  
  8.     $(function() {  
  9.         setInterval("GetTime()", 1000);  
  10.     });  
  11.   
  12.     function GetTime() {  
  13.         var mon, day, now, hour, min, ampm, time, str, tz, end, beg, sec;  
  14.         /*  
  15.         mon = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",  
  16.                 "Sep", "Oct", "Nov", "Dec");  
  17.         */  
  18.         mon = new Array("一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月",  
  19.                 "九月", "十月", "十一月", "十二月");  
  20.         /*  
  21.         day = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");  
  22.         */  
  23.         day = new Array("周日", "周一", "周二", "周三", "周四", "周五", "周六");  
  24.         now = new Date();  
  25.         hour = now.getHours();  
  26.         min = now.getMinutes();  
  27.         sec = now.getSeconds();  
  28.         if (hour < 10) {  
  29.             hour = "0" + hour;  
  30.         }  
  31.         if (min < 10) {  
  32.             min = "0" + min;  
  33.         }  
  34.         if (sec < 10) {  
  35.             sec = "0" + sec;  
  36.         }  
  37.         $("#Timer").html(  
  38.                 "<nobr>" + day[now.getDay()] + ", " + mon[now.getMonth()] + " "  
  39.                         + now.getDate() + ", " + now.getFullYear() + " " + hour  
  40.                         + ":" + min + ":" + sec + "</nobr>");  
  41.   
  42.     }  
  43. </script>  
  44. </head>  
  45. <body>  
  46.     <div style="background: pink; width: 200px;" id="Timer">  
  47. </body>  
  48. </html> 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值