Visit Mozilla.org

Core JavaScript 1.5 Reference:Global Objects:Date:toString

From MDC


Contents

[edit] Summary

Returns a string representing the specified Date object.

Method of Date
Implemented in: JavaScript 1.0, NES 2.0
ECMA Version: ECMA-262

[edit] Syntax

toString()

[edit] Parameters

None.

[edit] Description

The Date object overrides the toString method of the Object object; it does not inherit Object.toString. For Date objects, the toString method returns a string representation of the object.

JavaScript calls the toString method automatically when a date is to be represented as a text value or when a date is referred to in a string concatenation.

[edit] Examples

[edit] Example: Using toString

The following assigns the toString value of a Date object to myVar:

x = new Date();
myVar=x.toString();   //assigns a value to myVar similar to:
     //Mon Sep 28 14:36:22 GMT-0700 (Pacific Daylight Time) 1998

[edit] See also

Object.toString