YogeshChauhan . com

How to convert datetime to date format in JavaScript?

in JavaScript on November 21, 2020

We can format it using toDateString().

It convert any date into a readable string.

Example


var date = new Date();
var readable_date = date.toDateString();
console.log(readable_date);

// Tue Jun 09 2020

The toDateString() method converts the date (not the time) of a Date object into a readable string.

Our goal is to convert into date so we are not worried about time conversion in this post.

The method is supported by all major browsers.

You can convert any datetime format into a date format.

Example 2


var date = "2020-01-15T05:12:59Z";
var readable_date = new Date(date).toDateString();
console.log(readable_date);

// Wed Jan 15 2020

Example 3


var date = "2020-06-08T22:50:00.000+02:00";
var readable_date = new Date(date).toDateString();
console.log(readable_date);

// Mon Jun 08 2020
amazon

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Jun 16 What are Stored Procedures for SQL Server? Jun 16 What are Class Constants in PHP? Jun 15 A short basic guide on states in React Jun 15 How to define constants in PHP? Jun 15 How to define visibility for a property in PHP? Jun 15 How to use @if and @else in SCSS?

You might also like these

Is Software Really Eating The World? I don’t think soMiscJavaScript Number MethodsJavaScriptHow to Make a Simple Module with a Form and Menu Link in Drupal 7.x?DrupalAccessing and Setting features of JavaScript ObjectsJavaScriptHow to enable and disable button using JavaScript?JavaScriptHow to add menu to your WordPress theme?WordPressList of all Pseudo Elements in CSSCSSHow to Secure Web or Mobile Browsers?MiscHow to define constants in PHP?PHPRelative Length Units in CSSCSSHow to remove N/A from Radio Button list in Drupal?DrupalHow to define variables in SCSS (Sass)?SCSS