Date.setTime()

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

date.setTime(milliseconds)

Description

The setTime() method sets the time in the Date object to the argument milliseconds, an integer representing the number of milliseconds between midnight January 1, 1970 (GMT) to the desired date and time.

Example

The code in Listing 6.99 uses the setTime() method to set the date to November, 17, 2005 using milliseconds.

Listing 6.99 Setting the Date with the setTime() Method
 <html> <script language="JavaScript"> <!–– Hide //Create a Date object. theDate = new Date(); //Set the date to Nov. 17, 2005 theDate.setTime(1132203600000); //display the date document.write(theDate.toString()); //Hide End ––> ...

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.