JavaScript Warning – Date.prototype.toLocaleFormat is deprecated
Last Updated :
22 May, 2023
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' );
|
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" );
|
Output:
Warning: Date.prototype.toLocaleFormat is deprecated; consider using Intl.DateTimeFormat instead
Share your thoughts in the comments
Please Login to comment...