JavaScript setSeconds() Method
Example
Set the seconds field of the current time to 35:
var d = new Date();
d.setSeconds(35);
d Output result:
Try it »
Definition and Usage
The setSeconds() method is used to set the seconds field of a date object.
This method can be used to set the milliseconds.
Browser support





All major browsers support the setSeconds() method.
Syntax
Date
.setSeconds(
sec
,
millisec
)
Parameter value
| Parameters | Description |
|---|---|
| sec | Required. A value representing the seconds.
This value is an integer between 0 and 59: |
between 0 and 999. This parameter was 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 | Milliseconds from January 1, 1970 to the adjusted date. Before ECMAScript standardization, this method returned 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();
n Output result:
Try it »
JavaScript Date object