DEMO: http://jsfiddle.net/abc123/f6k3H/1/
Javascript:
var d = new Date();
var c = new Date('2013-06-15 03:00:00');
alert(formatDate(c));
alert(formatDate(d));
function formatDate(d)
{
var month = d.getMonth();
var day = d.getDate();
month = month + 1;
month = month + "";
if (month.length == 1)
{
month = "0" + month;
}
day = day + "";
if (day.length == 1)
{
day = "0" + day;
}
return month + '-' + day + '-' + d.getFullYear();
}
Without the use of RegEx, some oddities may occur....For example:
d.getMonth() + 1
The reason behind this is that getMonth is zero-based....
day = day + "";
if (day.length == 1)
{
day = "0" + day;
}
This is because single-digit hours, seconds, and minutes will be returned as a single digit, so adding a leading 0 fixes this. The same can also be applied to Month and Day if needed.