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); 

jsfiddle code here

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); 

fiddle


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -