Open In App

JavaScript Warning – Date.prototype.toLocaleFormat is deprecated

Last Updated : 22 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

This JavaScript warning Date.prototype.toLocaleFormat is deprecated; consider using Intl.DateTimeFormat instead occurs if user is using the non-standard Date.prototype.toLocaleFormat method.

Message:

Warning: Date.prototype.toLocaleFormat is deprecated; consider using Intl.DateTimeFormat instead

Error Type:

Warning. JavaScript execution won't be halted.

What Happened?

In the code the non-standard Date.prototype.toLocaleFormat method is used but it is depreciated.

Example 1: In this example, the method which is depreciated is used.  So the error has occurred.

Javascript




let day = new Date();
let date = day.toLocaleFormat('%B, %e. %A %Y'); // Warning here


Output:

Warning: Date.prototype.toLocaleFormat is deprecated; consider using Intl.DateTimeFormat instead

Example 2: In this example, the method which is depreciated is used.  So the error has occurred.

Javascript




let day = new Date();
day.toLocaleFormat("%Y%m%d"); // Warning here


Output:

Warning: Date.prototype.toLocaleFormat is deprecated; consider using Intl.DateTimeFormat instead

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads