冷面閻羅

          低調做人&&高調做事
          隨筆 - 208, 文章 - 3, 評論 - 593, 引用 - 0
          數據加載中……

          javascipt中的時間函數

          今天作程序的時候用到了,在javascipt中回去的時間。以前我們都是在java中獲取時間然后將時間傳到js中,這樣不好之處就是當進入頁面后,等了好長時間在用時間的話,你傳過來的時間就是進入頁面的時間。后來就自己編寫個類,實現。該類的代碼如下
          Date.prototype.format = function(format) //author: meizz
          {
          ??var o = {
          ????"M+" : this.getMonth()+1, //month
          ????"d+" : this.getDate(), ?? //day
          ????"h+" : this.getHours(),?? //hour
          ????"m+" : this.getMinutes(), //minute
          ????"s+" : this.getSeconds(), //second
          ????"q+" : Math.floor((this.getMonth()+3)/3),? //quarter
          ????"S" : this.getMilliseconds() //millisecond
          ??}
          ??if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
          ????(this.getFullYear()+"").substr(4 - RegExp.$1.length));
          ??for(var k in o)if(new RegExp("("+ k +")").test(format))
          ????format = format.replace(RegExp.$1,
          ??????RegExp.$1.length==1 ? o[k] :
          ????????("00"+ o[k]).substr((""+ o[k]).length));
          ??return format;
          }
          然后你要到的話只要這樣就可以,new Date().format("yyyy-MM-dd hh:mm:ss"),這個時間就是你點鼠標那一刻的時間。
          這就解決傳時間的bug。

          posted on 2006-10-24 18:30 冷面閻羅 閱讀(530) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 麻栗坡县| 神木县| 巴彦县| 资阳市| 团风县| 册亨县| 朝阳县| 沅陵县| 房产| 昌乐县| 昭觉县| 嘉祥县| 湖北省| 桃江县| 龙州县| 宜君县| 新沂市| 抚松县| 祁阳县| 信丰县| 闽侯县| 正阳县| 铁力市| 玉田县| 卢湾区| 徐水县| 山阳县| 彭山县| 绍兴县| 阳信县| 灵丘县| 广河县| 青岛市| 康定县| 三河市| 淮南市| 梓潼县| 隆德县| 大城县| 武邑县| 洪泽县|