JavaScript setSeconds()Method
Example
Set the seconds field of the current time to 35:
var d = new Date();
d.setSeconds(35);
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
![]()
![]()
![]()
![]()
![]()
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:
|
| millisec | Optional. A number representing the milliseconds. Between 0 and 999. This parameter is not supported before ECMAScript standardization:
|
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();
d.setSeconds(35,825);
var n=d.getSeconds() + ":" + d.getMilliseconds();
nOutput:
Try it Yourself »
Other Extensions
JavaScript Date Object