Latest web development tutorials

JavaScript setSeconds () method

Date Object Reference JavaScript Date Object

Examples

The current time in seconds field to 35:

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

d output:


try it"

Definition and Usage

The setSeconds () method is used to set the target date of the seconds field.

This method can be used to set the number of milliseconds.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support setSeconds () method.


grammar

Date.setSeconds( sec , millisec )

Parameter Value

参数 描述
sec 必需。表示秒的数值。

该值是介于 0 ~ 59 之间的整数:

  • -1 为前一分钟的最后一秒
  • 60 为下一分钟的第一秒
millisec 可选。表示毫秒的数值。

介于 0 ~ 999 之间。在 EMCAScript 标准化之前,不支持该参数:

  • -1 为前一秒钟的最后一毫秒
  • 1000 为下一秒钟的第一毫秒

return value

Type 描述
Number 1970年1月1日至调整过的日期的毫秒表示。在 ECMAScript 标准化之前,该方法什么都不返回。

technical details

JavaScript version: 1.0


More examples

Examples

Set the number of seconds and milliseconds:

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

n output:


try it"

Date Object Reference JavaScript Date Object