Skip to content
Related Articles

Related Articles

Improve Article

JavaScript Warning – Date.prototype.toLocaleFormat is deprecated

  • Last Updated : 26 Aug, 2020

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:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

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.




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

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.




<script>
  var day = new Date();
  day.toLocaleFormat("%Y%m%d"); // Warning here
</script>

Output:

Warning: Date.prototype.toLocaleFormat is deprecated; consider using Intl.DateTimeFormat instead
My Personal Notes arrow_drop_up
Recommended Articles
Page :