JavaScript Date Format - How do I format a date in JavaScript
JavaScript Date Format
- The JavaScript date object can be used to get a year, month and day. We can display a timer on the webpage with the help of a JavaScript date object.
- There are many types of date formats in JavaScript: ISO Date, Short Date, and Long Date. The formats of JavaScript's date are defined as follows.
- ISO date
- "2020-08-01" (The International Standard)
- Short date
- "01/08/2020"
- Long date
- "Aug 01 2020" or "01 Aug 2020"
JavaScript ISO date
- The ISO 8601 is the international standard for the times and dates, and the syntax (YYYY-MM-DD) of this standard is the preferred date format in JavaScript.
Sample Code
Output
1.This is a complete date format using ISO date.
- Sat Aug 01 2020 05:30:00 GMT+0530 (India Standard Time)
2.In this format, we specify only year and month (YYYY-MM) without day.
- Sat Aug 01 2020 05:30:00 GMT+0530 (India Standard Time)
JavaScript Short Date
- The "MM/DD/YYYY" is the format used to write short dates. Now, we understand the short date by using an example.
Sample Code
Output
JavaScript Long Date
- The "MMM DD YYYY" is the format used to write Long dates. The month and date can be written in any order, and it is allowed to write a month in abbreviated (Aug) form or in full (August).