JS Date Format Function DateFormat
varDateFormat =function(datetime, FORMATSTR) {varDAT =datetime; varstr =Formatstr; varWeek = [' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six ']; STR= Str.replace (/yyyy| yyyy/, Dat.getfullyear ()); STR= Str.replace (/yy| yy/, (dat.getyear ()%) > 9? (Dat.getyear ()%). ToString (): ' 0 ' + (dat.getyear ()% 100)); STR= Str.replace (/mm/, Dat.getmonth () > 9? (Dat.getmonth () + 1). ToString (): ' 0 ' + (dat.getmonth () + 1)); STR= Str.replace (/m/g, (Dat.getmonth () + 1)); STR= Str.replace (/w| w/g, Week[dat.getday ()]); STR= Str.replace (/dd| Dd/, Dat.getdate () > 9? Dat.getdate (). toString (): ' 0 ' +dat.getdate ()); STR= Str.replace (/d| d/g, dat.getdate ()); STR= Str.replace (/hh| hh/, Dat.gethours () > 9? Dat.gethours (). toString (): ' 0 ' +dat.gethours ()); STR= Str.replace (/h| h/g, dat.gethours ()); STR= Str.replace (/mm/, Dat.getminutes () > 9? dat.getminutes (). toString (): ' 0 ' +dat.getminutes ()); STR= Str.replace (/m/g, dat.getminutes ()); STR= Str.replace (/ss| ss/, Dat.getseconds () > 9? Dat.getseconds (). toString (): ' 0 ' +dat.getseconds ()); STR= Str.replace (/s| s/g, Dat.getseconds ()); returnSTR}
How to use
DateFormat (new Date (), ' yyyy-mm-dd '); // 2017-01-20
Note: Uppercase m indicates the month, and lowercase m indicates minutes;
JS date Format function (customizable)