javascriptjquery

Format date to MM/dd/yyyy in JavaScript


I have a dateformat like this '2010-10-11T00:00:00+05:30'. I have to format in to MM/dd/yyyy using JavaScript or jQuery . Anyone help me to do the same.


Solution

  • 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))) + '/' + ((date.getDate() > 9) ? date.getDate() : ('0' + date.getDate())) + '/' + date.getFullYear());