- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript Date Formats
To implement date formats in JavaScript, the code is as follows −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample { font-size: 18px; font-weight: 500; } </style> </head> <body> <h1>Date Format</h1> <div class="sample"></div> <button class="Btn">CLICK HERE</button> <h3>Click on the above button to see the different date formats</h3> <script> let fillEle = document.querySelector(".sample"); let date = []; date.push(new Date('2020-01-20')); date.push(new Date('2020-02')); date.push(new Date('2020')); date.push(new Date("2015-03-25T12:00:00Z")); fillEle.innerHTML = date + '<br>'; document.querySelector(".Btn").addEventListener("click", () => { date.forEach(item=>{ fillEle.innerHTML += item + '<br>' }) }); </script> </body> </html>
Output
On clicking the “CLICK HERE” button −
- Related Articles
- How to insert date in single quotes with MySQL date formats?
- Java Program to set date formats for different countries
- How to insert date record to the same table with different date formats with MySQL?
- How can we map multiple date formats using Jackson in Java?
- How to validate given date formats like MM-DD-YYYY using regex in java?
- What are Instruction Formats?
- How to use Formats in Perl?
- JavaScript date.@@toPrimitive() function
- JavaScript Date constructor Property
- JavaScript - Get Date Methods
- JavaScript Set Date Methods
- How to convert epoch Date to meaningful JavaScript date?
- How to create JavaScript Date object from date string?
- How to convert a MySQL date to JavaScript date?
- Python program to display various datetime formats

Advertisements