1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67-68 |
Date.prototype.tostring=function (format,loc) {var time={}; Year=this.getfullyear (); Time. Tyear= ("" +time). Year). substr (2); Time. Month=this.getmonth () +1; Time. Tmonth=time. Month<10? " 0 "+time. Month:time. Month; Time. Day=this.getdate (); Time. Tday=time. Day<10? " 0 "+time. Day:time. Day; Time. Hour=this.gethours (); Time. Thour=time. Hour<10? " 0 "+time. Hour:time. Hour; Time.hour=time. Hour<13?time. Hour:time. Hour-12; Time. Thour=time.hour<10? " 0 "+time.hour:time.hour; Time. Minute=this.getminutes (); Time. Tminute=time. Minute<10? " 0 "+time. Minute:time. Minute; Time. Second=this.getseconds (); Time. Tsecond=time. Second<10? " 0 "+time. Second:time. Second; Time.millisecond=this.getmilliseconds (); Time. Week=this.getday (); var mmmarren=[, "Feb", "Mar", "APR", "may", "June", "O", "Aug", "Sep", "Oct", "Nov", "Dec"]; var mmmarr=["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; var weekarren=["Sun", "Mon", "Tue", "Web", "Thu", "Fri", "Sat"]; var weekarr=["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; Var onumber=time. millisecond/1000; if (format!=undefined && format.replace (/s/g, ""). Length>0) {if (loc!=undefined && loc = "en") {mmmarr=mmmarren.slice (0); Weekarr=weekarren.slice (0); } format=format. replace (/yyyy/ig,time. year). Replace (/yyy/ig,time. year). Replace (/yy/ig,time. tyear). replace (/y/ig,time. tyear). replace (/mmm/g,mmmarr[time. MONTH-1]). replace (/mm/g,time. tmonth). replace (/m/g,time. Month). replace (/dd/ig,time. tday). replace (/d/ig,time. Day). Replace (/hh/g,time. Thour). replace (/h/g,time. Hour). replace (/hh/g,time. Thour). Replace (/h/g,time.hour). replace (/mm/g,time. Tminute). replace (/m/g,time. Minute). replace (/ss/ig,time. Tsecond). replace (/s/ig,time. Second). replace (/fff/ig,time. millisecond). Replace (/ff/ig,onumber.tofixed (2) *100). Replace (/f/ig,onumber.tofixed (1) *10). Replace (/eee/g, Weekarr[time. Week]); } else{format=time. year+ "-" +time. month+ "-" +time. Day+ "" +time. hour+ ":" +time. Minute+ ":" +time. Second; } return format; } var d=new Date (); Console.log (D.tostring ()); 2014-7-27 9:26:52 Console.log (d.tostring ("")); 2014-7-27 9:26:52 Console.log (d.tostring ("Yyyy-mm-dd HH:mm:ss")); 2014-07-27 09:26:52 Console.log (d.tostring ("YYYY year mm month DD Day HH:mm:ss"); July 27, 2014 09:26:52 Console.log (d.tostring ("Yyyy-mm-dd HH:mm:ss FFF")); 2014-07-27 09:26:52 237 Console.log (d.tostring ("yyyy MMM DD EEE")); July 2014 27 weeks Five Console.log (d.tostring ("yyyy MMM DD EEE", "en")); 2014 June Fri |