posts - 1,  comments - 6,  trackbacks - 0
          在JS中獲取系統當前時間是用到Date這個對象,在實際應用時,常常會用到不同的顯示格式,下面是一些處理方法!
          ? var now = new Date();
          ? strTime = now.toLocaleString();
          ? strYear = now.getYear();
          ? strMonth = now.getMonth();
          ? strDay = now.getDay();
          ?? 如果要將時間顯示為2007/02/12這種格式,人們往往會采用如下的方式:
          ?? displayTime = strYear +"/"+strMonth+"/"+strDay;
          ?? 也可以加入一些判斷,以滿足要求,但在實際中這種辦法是做不到的,顯示的格式與我們期望的要求,有很大的差別,為了可以滿足要求我們做如下的處理,
          ?? if(strTime.substring(5,6)<10){
          ?var displayTime = strTime.substring(0,4)+"/0"+strTime.substring(5,6)+"/"+strTime.substring(7,9);
          ?}else{
          ?var displayTime = strTime.substring(0,4)+"/"+strTime.substring(5,7)+"/"+strTime.substring(8,10);
          ?}
          這樣做雖然有些麻煩,但具有很強的靈活性。
          posted on 2007-02-12 14:21 Andy zhang 閱讀(9233) 評論(6)  編輯  收藏


          FeedBack:
          # re: 關于JS獲取系統當前時間
          2007-04-27 17:17 | dfsa
          fdsaf  回復  更多評論
            
          # re: 關于JS獲取系統當前時間
          2008-02-03 10:09 | 1
          你 說的不對 strDay = now.getDay(); 是對應日期的星期幾而不是你說的2007/02/12  回復  更多評論
            
          # re: 關于JS獲取系統當前時間
          2008-07-30 16:27 | rzzfch520
          if(strTime.substring(5,6)<10){
          var displayTime = strTime.substring(0,4)+"/0"+strTime.substring(5,6)+"/"+strTime.substring(7,9);
          }else{
          var displayTime = strTime.substring(0,4)+"/"+strTime.substring(5,7)+"/"+strTime.substring(8,10);
          }

          這樣做是不可能實現的if(strTime.substring(5,6)<10)這一句就有問題,應該是
          if(strTime.substring(5,6) > 0)
          然后還需要同樣的同日進行判斷  回復  更多評論
            
          # re: 關于JS獲取系統當前時間
          2008-09-05 09:16 | zf
          恩 這段代碼有問題  回復  更多評論
            
          # re: 關于JS獲取系統當前時間[未登錄]
          2008-10-06 22:28 | dd
          @1
          就是  回復  更多評論
            
          # re: 關于JS獲取系統當前時間
          2008-12-30 13:24 | 北京時間
          你說的不對 strDay = now.getDay(); 是對應日期的星期幾而不是你說的2007/02/12   回復  更多評論
            

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


          網站導航:
           
          <2008年2月>
          272829303112
          3456789
          10111213141516
          17181920212223
          2425262728291
          2345678

          常用鏈接

          留言簿(1)

          隨筆檔案

          搜索

          •  

          最新評論

          主站蜘蛛池模板: 星子县| 上杭县| 达拉特旗| 调兵山市| 方正县| 西充县| 卓资县| 盘锦市| 平山县| 韶山市| 台中市| 安阳市| 万源市| 个旧市| 平山县| 新源县| 崇信县| 汶上县| 上杭县| 沁水县| 平阳县| 从化市| 连平县| 鹿邑县| 濮阳县| 昌平区| 贡山| 龙州县| 固阳县| 策勒县| 册亨县| 宜兴市| 镇雄县| 逊克县| 桂林市| 嘉禾县| 时尚| 磐安县| 博爱县| 鹤岗市| 二连浩特市|