JavaScript setUTCSeconds()Method

Date 对象参考手册JavaScript Date Object

Example

Set the seconds field of the current time to 35 according to UTC:

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

dOutput:


Try it Yourself »

Definition and Usage

The setUTCSeconds() method is used to set the seconds field of a specified time according to UTC.

This method is applicable for setting the seconds field of a specified time.

Tip:Coordinated Universal Time, also known as Universal Time Coordinated, World Standard Time, International Coordinated Time, abbreviated as UTC.

Note:UTC time is the same as GMT (Greenwich) time.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the setUTCSeconds() method.


Syntax

Date.setUTCSeconds(sec,millisec)

Parameter Values

Parameter Description
sec

Required. The value to set for the seconds field of the dateObject, expressed in UTC.

This parameter 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. The value to set for the milliseconds field of the dateObject, expressed in UTC.

This parameter is an integer between 0 and 999:

  • -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 of the adjusted date.

Technical Details

JavaScript Version: 1.3


More Examples

Example

Set the seconds and milliseconds according to UTC:

var d = new Date();
d.setUTCSeconds(35,825);
var n=d.getUTCSeconds() + ":" + d.getUTCMilliseconds();

nOutput:


Try it Yourself »


Date 对象参考手册JavaScript Date Object

Other Extensions