How do I format a date in JavaScript?

Created by ajeet kanojiaLinked to 61.2m issues across 243 teams

tl;dr

Here's how to format a date in JavaScript:

If you need to format a date in JavaScript, you can use the Date#toLocaleDateString method. This method allows you to specify the language whose formatting conventions should be used, and to create locale-specific rendering. You can specify the representation of the day, weekday, year, month, and hour. Possible values for each of these are "numeric" (day, year, month, hour, minute, second), "2-digit" (day, year, month, hour, minute, second), "narrow" (weekday, month), "short" (weekday, month), and "long" (weekday, month).

We use cookies to personalize content
run ads, and analyze traffic.