Is there a built-in function or plugin to handle date formatting in JavaScript?
No, there is nothing built-in for Date
objects, but there are a bunch of libraries to deal with and format them:
- date.js
- moment.js
- XDate
- Date and Date.Extras in Mootools
- Date in Sugar
- Dojo.date
- a few functions in Mochikit
-
DateFormat (only PHP's
date
) - date at php.js
- DataType in YUI, especially for i18n
- date-functions.js, used especially by JQuery datetimepicker plugin
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.