jquery - Zero Padding a Date with JavaScript -
i want format date this:
may 02 2013
but @ moment, formatting looks this:
may 2 2013
how can 0 pad type of date day in date 02
instead of 2
?
here code using:
var m_names = new array("january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"); var d = new date(); var curr_date = d.getdate(); var curr_month = d.getmonth(); var curr_year = d.getfullyear(); alert( m_names[curr_month] + " " +curr_date + " " + curr_year);
try this:
var d = new date(); var curr_date = ("0" + d.getdate()).slice(-2); var curr_month = d.getmonth(); var curr_year = d.getfullyear(); alert( m_names[curr_month] + " " +curr_date + " " + curr_year);
Comments
Post a Comment