JavaScript Date setSeconds() Method

Definition and Usage

setSeconds() Method to set the seconds of the date object.

This method can also be used to set milliseconds.

Instance

Example 1

Set the seconds to 35:

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

Try It Yourself

Example 2

Set Seconds and Milliseconds:

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

Try It Yourself

Syntax

Date.setSeconds(sec, millisec)

Parameter Value

Parameter Description
sec

Required. Represents the integer of seconds.

Expected value is 0-59, but other values are allowed:

  • -1 will cause the last second of the previous minute
  • 60 will cause the first second of the next minute
millisec

Optional. Represents the integer of milliseconds.

Expected value is 0-999, but other values are allowed:

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

Technical Details

Return Value: A number representing the milliseconds between the date object and midnight of January 1, 1970.
JavaScript Version: ECMAScript 1

Browser Support

Method Chrome IE Firefox Safari Opera
setSeconds() Support Support Support Support Support

Related Pages

Tutorial:JavaScript Date

Tutorial:JavaScript Date Format

Tutorial:JavaScript Date Setting Methods