- 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
How to format date value in JavaScript?
Example
Following is the code to format date value in JavaScript −
function changeDateFormat(dateValues, addToFront = "") { return typeof dateValues == "object" ? addToFront + dateValues.toLocaleDateString() : ""; } var currentDate = new Date(); console.log("The current date values=" + currentDate); console.log("After formatting date values=" + changeDateFormat(currentDate));
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo289.js.
Output
This will produce the following output on console −
PS C:\Users\Amit\javascript-code> node demo289.js The current date values=Sat Aug 29 2020 12:51:06 GMT+0530 (India Standard Time) After formatting date values=8/29/2020
- Related Articles
- How to format a JavaScript date?
- How to format JavaScript date into yyyy-mm-dd format?
- Format date value in MongoDB shell?
- Extract Numeric Date Value from Date Format in MySQL?
- Check valid date format in JavaScript?
- How to format date in JSP?
- How to convert Python date format to 10-digit date format for mysql?
- How to convert a date object to string with format hh:mm:ss in JavaScript?
- How to format date string in PowerShell?
- How to convert MySQL DATETIME value to JSON format in JavaScript?
- How to convert US date format to MySQL format in INSERT query?
- Java Program to parse string date value with default format
- How to change date time format in HTML5?
- How to update the date format in MySQL?
- How to format date and time in android?

Advertisements