Date.toSource() (Method)

Outputs a date formatted as a Date literal contained in a string.

Availability:

ECMAScript edition - 3
JavaScript - 1.3
JScript - 3.0
Internet Explorer - 4.0
Netscape - 4.06
Property/method value type:String primitive
JavaScript syntax:-myDate.toSource()

This is an alternative way to deliver a string version of a date value. In this case, it is formatted as a Date literal and can then be used in an eval() function to assign another date.

If you run the example below, it should yield something resembling this:

(new Date(961700949597))

Note that the date value is in milliseconds UTC time, and will vary, but you should see a very long number like that.

Example code:

   // Create a date object and display its source

   myObject = new Date();

   document.write(myObject.toSource());

See also:Date.prototype, Date.toString()