Sorry to resurrect and older post, but this seems silly to me. I wonder if formatting date/time Strings was an oversight or intentionally left out because this seems like a basic function of a scripting language.
Edit - Also, I tested this that works without having to use so many ternary if statements:
Code:function yyyyMMdd_hhmmss(d) { var arrDate = d.toString().split(/ |:/); var yyyy = arrDate[3]; var MM = ((d.getMonth() < 10) ? "0": "") + (d.getMonth()+1); var dd = arrDate[2]; var hh = arrDate[4]; var mm = arrDate[5]; var ss = arrDate[6]; return yyyy + MM + dd + '_' + hh + mm + ss; }




Reply With Quote