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 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
Social Media Colors: LESS VariablesMiscellaneousadd_filter function in WordPressWordPressDISTINCT ON: The confusing, unique and useful feature in PostgresPostgresWordPress: How to get field values in Advanced Custom Fields?WordPressThe basics of CSS Box modelCSSWhat are CSS Specificity Rules and how does browser apply them?CSSWhat is PostgreSQL? How similar or different it is from SQL?PostgresSome Useful Operators in The SQL WHERE ClauseSQL/MySQLHow to add MySQL alternate port and sockets/pipes in WordPress?WordPressHow to redirect or load a new document using JavaScript?JavaScriptinclude, include_once, require, require_once in PHPPHPThe simple difference between var, let and const in JavascriptJavaScript