Format date to MM/dd/yyyy in JavaScript [duplicate]

Try this; bear in mind that JavaScript months are 0-indexed, whilst days are 1-indexed.

var date = new Date('2010-10-11T00:00:00+05:30');
    alert(((date.getMonth() > 8) ? (date.getMonth() + 1) : ('0' + (date.getMonth() + 1))) + "https://stackoverflow.com/" + ((date.getDate() > 9) ? date.getDate() : ('0' + date.getDate())) + "https://stackoverflow.com/" + date.getFullYear());

Leave a Comment