JavaScript Date setUTCSeconds() Method

Definition and Usage

setUTCSeconds() The method sets the seconds of the date object according to UTC time.

This method can also be used to set milliseconds.

Tip:Coordinated Universal Time (UTC) is the time set by the world time standard.

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

Instance

Example 1

Set the seconds to 35 according to UTC time:

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

Try It Yourself

Example 2

Set seconds and milliseconds according to UTC:

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

Try It Yourself

Syntax

Date.setUTCSeconds(sec, millisec)

Parameter Value

Parameter Description
sec

Required. Represents the integer part of seconds.

The 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 part of milliseconds.

The 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 on January 1, 1970.
JavaScript Version: ECMAScript 1

Browser Support

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

Related Pages

Tutorial:JavaScript Date

Tutorial:JavaScript Date Format

Tutorial:JavaScript Date Setting Methods