JavaScript setSeconds()Method

Date 对象参考手册JavaScript Date Object

Example

Set the seconds field of the current time to 35:

var d = new Date();
d.setSeconds(35);

dOutput:


Try it Yourself »

Definition and Usage

The setSeconds() method is used to set the seconds field of a Date object.

This method can also be used to set the milliseconds.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the setSeconds() method.


Syntax

Date.setSeconds(sec,millisec)

Parameter Values

Parameter Description
sec Required. A number representing the seconds.

The value is an integer between 0 and 59:

  • -1 is the last second of the previous minute
  • 60 is the first second of the next minute
millisec Optional. A number representing the milliseconds.

Between 0 and 999. This parameter is not supported before ECMAScript standardization:

  • -1 is the last millisecond of the previous second
  • 1000 is the first millisecond of the next second

Return Value

Type Description
Number The millisecond representation from January 1, 1970 to the adjusted date. Before ECMAScript standardization, this method returns nothing.

Technical Details

JavaScript Version: 1.0


More Examples

Example

Set the seconds and milliseconds:

var d = new Date();
d.setSeconds(35,825);
var n=d.getSeconds() + ":" + d.getMilliseconds();

nOutput:


Try it Yourself »

Date 对象参考手册JavaScript Date Object

Other Extensions