Date.toLocaleString()

JavaScript 1.0+, ECMAScript 1.0+, JScript 1.0+ Nav2+, IE 3+ Syntax

							date.toLocaleString()

Description

The toLocaleString() method returns a string representation of the Date object in the local time zone. The format of the string can vary greatly, depending on the user's date and time format settings.

Example

The code in Listing 6.109 creates a Date object that contains the current date and time. The toLocaleString() method returns the date and time as a string using the local time zone.

Listing 6.109 Converting Date and Time to the Local Time Zone with the toLocaleString() Method
 <html> <script language="JavaScript"> <!–– Hide //Create a Date object. theDate = new Date(); //Display date and time string document.write(theDate.toLocaleString()); ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.