Is there a built-in function or plugin to handle date formatting in JavaScript?

后端 未结 3 1503
眼角桃花
眼角桃花 2020-11-30 14:40

Currently I need to output a date in a: \'5 October, 2012\' type format. Meaning day-of-month with no leading zeros, space, full month name, comma, space, four-digit year. I

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 15:17

    You've got some extraneous code that you can clean up:

    var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
        today = new Date(),
        completeDate = today.getDate() + " " + months[today.getMonth()] + ", " + today.getFullYear();
    
    $('#theEndDate').html(completeDate);
    

    Using a library isn't always the answer, especially if you are only going to use it in one spot.

提交回复
热议问题