Date to Date.prototype.toLocaleString()
It returns a string representation of this date object.
Example: The code creates a Date object representing a specific date and time, converts it to a localized string, and logs the result.
Javascript
let d = new Date(Date.UTC(2020, 9, 26, 7, 0, 0)); let result = d.toLocaleString(); console.log( "Date and Time of apocalypse: " + result); |
Output
Date and Time of apocalypse: 10/26/2020, 7:00:00 AM
JavaScript Object toLocaleString() Method
The Object.prototype.toLocaleString() method returns a local specific string representation of this object using the locale of the environment. Derived objects like an array, number, date, typedarray, and BigInt can override this method.
Syntax:
object.toLocaleString()
Return Value: It returns a string representation of this object.
Objects overriding toLocaleString():
Contact Us