Yogesh Chauhan's Blog

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.


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

// 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();

// Wed Jan 15 2020

Example 3

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

// Mon Jun 08 2020

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 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
How to create a function in SCSS (Sass)?SCSSfor @each loop in SCSSSCSSHow to add Read More Read Less Button using JavaScript?JavaScriptHow to define constants in PHP?PHPHow to compress images with gulp in WordPress?WordPressHow to create a flip pricing table using CSS and JavaScript?CSSControl rendering using CSS content-visibility propertyCSSWhat is the difference between Loosely Typed Language and Strongly Typed Language?MiscellaneousWordPress: How to access first and random row values from a repeater field in ACF?WordPressCheck if mixin is being called in a style rule or not in SCSSSCSSHow to refresh a page using PHP at regularly occurring intervals?PHPWordPress: How to setup and get values from an ACF options page?WordPress