Blogging my journey of learning Full stack devlopment and creating an App to get a hands on knowledge.

Search This Blog

Monday, 30 January 2023

How to convert String representation of Date to your Local Date Format in JavaScript React

You can convert the date string based on your current locations format by using following ways by using Date object.


Date.prototype.toLocaleDateString()

Syntax: 

toLocaleDateString()
toLocaleDateString(locales)

Example:

toLocaleDateString()

var date = new Date(e);
//e is an event with value on Jan 30 2023 00:00:00 GMT-0600 (Central Standard Time)
date.toLocaleDateString();
//Output : 1/30/2023

toLocaleDateString(locales): In order to get the format of the language used in the user interface of your application, make sure to specify that language (and possibly some fallback languages) using the locales argument

var date = new Date(e);
//e is an event with value on Jan 30 2023 00:00:00 GMT-0600 (Central Standard Time)
date.toLocaleDateString("en-GB");
//Output : 30/01/2023 format that British English uses day-month-year order

0 comments:

Post a Comment

Featured Post

Invoice Portal Project Links

Web App link for Invoice Portal  Invoice Portal App lets an user view and create an Invoice. Features: View the list of Number of Invoices b...

Powered by Blogger.

Popular Posts