Good day,
Is there a Regex that I could use to prepend a 0 before any number that is below 10?
I am not looking for a date parsing library, ternary or if/else solutions. (hopefully)
var currentDate = new Date(),
stringDate = currentDate.getFullYear() + "-" + currentDate.getMonth() + "-" + currentDate.getDate() + " " + currentDate.getHours() + ":" + currentDate.getMinutes() + ":" + currentDate.getSeconds();
alert( stringDate ); //2011-10-17 10:3:7
I would like a RegExp that I could apply to stringDate to get 2011-10-17 10:03:07
Thank you very much!
Just add the leading 0 every time, then use
slice(-2)to get the last two characters, like so: