emu in blogjava

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            171 隨筆 :: 103 文章 :: 1052 評(píng)論 :: 2 Trackbacks

          emu 2003年5月發(fā)表在 http://search.csdn.net/Expert/topic/1779/1779160.xml 上。

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
          <HTML>
          <HEAD>
          <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
          <TITLE>emu's date simple date formatter</TITLE>
          <META NAME="Generator" CONTENT="EditPlus">
          <META NAME="Author" CONTENT="emu">
          <META NAME="Keywords" CONTENT="date formatter format emu">
          <META NAME="Description" CONTENT="A function to format Date object into String">
          </HEAD>

          <BODY>
          <SCRIPT LANGUAGE="JavaScript">
          <!--
          Date.prototype.format = function (format){
           if (format == null) format = "yyyy/MM/dd HH:mm:ss.SSS";
           var year = this.getFullYear();
           var month = this.getMonth();
           var sMonth = ["January","February","March","April","May","June","July","August","September","October","November","December"][month];
           var date = this.getDate();
           var day = this.getDay();
           var hr = this.getHours();
           var min = this.getMinutes();
           var sec = this.getSeconds();
           var daysInYear = Math.ceil((this-new Date(year,0,0))/86400000);
           var weekInYear = Math.ceil((daysInYear+new Date(year,0,1).getDay())/7);
           var weekInMonth = Math.ceil((date+new Date(year,month,1).getDay())/7);
           return format.replace("yyyy",year).replace("yy",year.toString().substr(2)).replace("dd",(date<10?"0":"")+date).replace("HH",(hr<10?"0":"")+hr).replace("KK",(hr%12<10?"0":"")+hr%12).replace("kk",(hr>0&&hr<10?"0":"")+(((hr+23)%24)+1)).replace("hh",(hr>0&&hr<10||hr>12&&hr<22?"0":"")+(((hr+11)%12)+1)).replace("mm",(min<10?"0":"")+min).replace("ss",(sec<10?"0":"")+sec).replace("SSS",this%1000).replace("a",(hr<12?"AM":"PM")).replace("W",weekInMonth).replace("F",Math.ceil(date/7)).replace(/E/g,["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][day]).replace("D",daysInYear).replace("w",weekInYear).replace(/MMMM+/,sMonth).replace("MMM",sMonth.substring(0,3)).replace("MM",(month<9?"0":"")+(month+1));
          }

          var d = new Date();
          alert(d.format());//default format
          alert(d.format("MM-dd-yyyy"));
          alert(d.format("dd/MM/yy"));
          alert(d.format("dd\\MM\\yyyy HH:mm ss.SSS"));
          alert(d.format("yyyy年MM月dd日 HH時(shí)mm分ss.SSS秒"));
          alert(d.format("yyyy年MM月dd日 E  HH(0~23)時(shí)mm分ss.SSS秒"));
          alert(d.format("yyyy年MM月dd日 E  KK(0~11)時(shí)mm分ss.SSS秒 a"));
          alert(d.format("yyyy年MM月dd日 E  hh(1~12)時(shí)mm分ss.SSS秒 a"));
          alert(d.format("yyyy年MM月dd日 E  kk(1~24)時(shí)mm分ss.SSS秒 今年的第D天,第w周,MMMM這個(gè)月的第W周,MMM這個(gè)月的第F個(gè)E"));
          //-->
          </SCRIPT>
          </BODY>
          </HTML>

          posted on 2005-12-26 11:19 emu 閱讀(1441) 評(píng)論(2)  編輯  收藏 所屬分類(lèi): DHTML和JAVASCRIPT 技術(shù)

          評(píng)論

          # 補(bǔ)充一個(gè)中文日期格式 2006-04-05 09:27 emu
          <SCRIPT LANGUAGE="JavaScript">
          <!--
          String.prototype.toCHS=function(){return this.replace(/\d/g, function(a){return "零一二三四五六七八九".charAt(parseInt(a))});}
          Number.prototype.toCHS=function(){return((this>19?Math.floor(this/10):"")+(this>9?("十"):"")+(this%10==0&&this>0?"":this%10)).toCHS();}
          Date.prototype.toCHS=function(){
          with(this)return(getFullYear()+"").toCHS()+"年"+(getMonth()+1).toCHS()+"月"+getDate().toCHS()+"日"+getHours().toCHS()+"時(shí)"+getMinutes().toCHS()+"分"+getSeconds().toCHS()+"秒";
          }
          alert(new Date().toCHS());
          //-->
          </SCRIPT>  回復(fù)  更多評(píng)論
            

          # re: script 版的日期格式函數(shù) 2006-04-05 10:15 emu
          再來(lái)一個(gè),這下可以稱最簡(jiǎn)版了吧?

          <SCRIPT LANGUAGE="JavaScript">
          <!--
          function toCHS(s){return s.constructor!=Number?s.constructor!=String?s.constructor!=Date?null:toCHS(s.getFullYear()+"")+"年"+toCHS(s.getMonth()+1)+"月"+toCHS(s.getDate())+"日"+toCHS(s.getHours())+"時(shí)"+toCHS(s.getMinutes())+"分"+toCHS(s.getSeconds())+"秒":s.replace(/\d/g,function(a){return"零一二三四五六七八九".charAt(parseInt(a))}): toCHS(((s>19?Math.floor(s/10):"")+(s>9?("十"):"")+(s%10==0&&s>0?"":s%10)))}
          alert(toCHS(new Date()));
          //-->
          </SCRIPT>  回復(fù)  更多評(píng)論
            

          主站蜘蛛池模板: 龙井市| 永年县| 江油市| 高邮市| 绵竹市| 平凉市| 平度市| 吉林省| 邯郸市| 湘乡市| 扎囊县| 盐源县| 保靖县| 达拉特旗| 峨眉山市| 土默特左旗| 樟树市| 合肥市| 锡林郭勒盟| 徐水县| 宣化县| 吉首市| 古交市| 社会| 子长县| 大英县| 汪清县| 潞西市| 光泽县| 琼中| 嘉兴市| 库车县| 蓬溪县| 北安市| 内黄县| 桃园县| 花垣县| 宝坻区| 东明县| 黎平县| 土默特左旗|