Date.toString()

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

							date.toString()

Description

The toString() method returns a string representation of the Date object in the local time zone.

Note

How does the toString() method differ from toGMTString() and toLocaleString()? Unlike the toGMTString() method, the toString() method displays the date in the local time zone. The toString() does not always display the date in the local format of the toLocaleString() method.

Example

The code in Listing 6.111 creates a Date object from the current date and time. The toString() method is then used to display the date as a string in the local time zone.

Listing 6.111 Accessing Date as a String with the toString() Method ...

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.