JavaScript convert date to long date format

JavaScript date is a function to convert a date string to a parsed date format. It could be a long date format, short date format, medium date format or any other. Here is a JavaScript code to convert date to long date format.


Convert date to long date format

JavaScript is a largely liked and used scripting language throughout the world. Consider code below to convert the date.

Code explanation

I have taken two constant arrays MONTHSand DAYSto store the long months and days respectively. I will use them to extract month and day based on the provided date.

The function getLongDatedoes all the work. It checks the provided formats and extracts the date, month and year based on them and then return the formatted date.

I have put a condition to check whether the formats provided are correct for the long date or not. If not, I have returned an error message stating that format is invalid.

Code demo

Here is a working code demo in jsFiddle.

Conclusion

JavaScript date is a function which is useful for date string parse and convert it to date. We use the function to format a date as per our requirement.

Read: JavaScript check if a string is binary

Also Read: More JavaScript Articles

1 thought on “JavaScript convert date to long date format

  1. Pingback: Best Sites To Learn JavaScript for FREE | WebTutorialOnline | Programming News | Software Development | Web Development

Leave a Reply

Your email address will not be published. Required fields are marked *