-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat-date.min.js
7 lines (6 loc) · 1.03 KB
/
format-date.min.js
1
2
3
4
5
6
7
//-------------------formatDate Usage-------------------//
//
// formatDate(new Date(), 'YYYY MMMM DD');
//
//-----------------formatDate Usage-END-----------------//
function formatDate(a,b){function h(a){var b=new Date-a,c=3154e7,d=2628e6,e=864e5,f=36e5,g=6e4;return b/c>=1?b/c<2?"1 year":Math.round(b/c)+" years":b/d>=1?b/d<2?"1 month":Math.round(b/d)+" months":b/e>=1?b/e<2?"1 day":Math.round(b/e)+" days":b/f>=1?b/f<2?"1 hour":Math.round(b/f)+" hours":b/g>=1?b/g<2?"1 minute":Math.round(b/g)+" minute":"less than a minute"}var c=["January","February","March","April","May","June","July","August","September","October","November","December"],d=["Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec"],e=function(a){return a<10?"0"+a:a},f={YYYY:a.getFullYear(),YY:a.getFullYear().toString().slice(2),MMMM:c[a.getMonth()],MM:d[a.getMonth()],M:e(a.getMonth()+1),DD:e(a.getDate()),hh:e(a.getHours()),mm:e(a.getMinutes()),ss:e(a.getSeconds()),ms:e(a.getMilliseconds()),"%dif%":h(a)},g=b;for(key in f)g=g.replace(key,f[key]);return g}