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:

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 :