-
Notifications
You must be signed in to change notification settings - Fork 0
/
Date_format.min.js
2 lines (2 loc) · 2.05 KB
/
Date_format.min.js
1
2
/* Date.format() v0.1 by Geoffray Warnants */
Date.prototype.format=function(a){var b=function(a){switch(a){case"d":return c.getDate()<10?"0"+c.getDate():c.getDate();case"D":return c.toDateString().split(" ")[0];case"j":return c.getDate();case"l":return["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][c.getDay()];case"N":return(e=c.getDay())==0?7:e;case"S":e=["st","nd","rd"];return typeof e[c.getDate()-1]!=="undefined"?e[c.getDate()-1]:"th";case"w":return c.getDay();case"z":for(var d=0,e=c.getDate()-1;d<c.getMonth();d++){e+=(new Date(c.getFullYear(),d+1,0)).getDate()}return e;case"W":return(e=Math.ceil(b("z")/7))<10?"0"+e:e;case"F":return["January","February","March","April","May","June","July","August","September","October","November","December"][c.getMonth()];case"m":return c.getMonth()<9?"0"+(1+c.getMonth()):1+c.getMonth();case"M":return c.toDateString().split(" ")[1];case"n":return 1+c.getMonth();case"t":return(new Date(c.getFullYear(),1+c.getMonth(),0)).getDate();case"L":return c.getYear()%4&&!c.getYear()%100||c.getYear()%400?1:0;case"Y":return c.getFullYear();case"y":return(e=c.getFullYear()%100)<10?"0"+e:e;case"a":return b("A").toLowerCase();case"A":return c.getHours()<12?"AM":"PM";case"B":return Math.floor((c.getHours()*3600+c.getMinutes()*60+c.getSeconds())/86.4);case"g":return(e=c.getHours()%12)!=0?e:12;case"G":return c.getHours();case"h":return(e=b("g"))!=0?e<10?"0"+e:e:12;case"H":return c.getHours()<10?"0"+c.getHours():c.getHours();case"i":return c.getMinutes()<10?"0"+c.getMinutes():c.getMinutes();case"s":return c.getSeconds()<10?"0"+c.getSeconds():c.getSeconds();case"u":return c.getMilliseconds()*1e3;case"O":var f=c.getTimezoneOffset();var g=Math.floor(Math.abs(f)/60);var h=Math.abs(f)%60;return(f<0?"+":"-")+(g<10?"0"+g:g)+(h<10?"0"+h:h);case"P":e=b("O");return e.substr(0,3)+":"+e.substr(3,2);case"Z":return-60*c.getTimezoneOffset();case"c":return c.toISOString();case"U":return Math.round(c.getTime()/1e3)}return a};var c=this,d;return a.replace(/\\?[dDmjwYHisFlSLMntyAaGghucUNzWBOPZ]/g,function(a,c,d,e){return a.length==1?b(a):a})}