Date setUTCSeconds() Method - Javascript Date

Javascript examples for Date:setUTCSeconds

Description

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

UTC time is the same as GMT time.

Syntax

date.setUTCSeconds(sec,millisec)

Parameter Values

Parameter Description
sec Required. An integer representing the seconds
millisec Optional. An integer representing the milliseconds

sec expected values are 0-59, but other values are allowed:

  • -1 sets the last second of the previous minute
  • 60 sets the first second of the next minute

millisec expected values are 0-999, but other values are allowed:

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

Return Value:

A Number, representing the number of milliseconds between the date object and midnight January 1 1970

display seconds and milliseconds after changing both of them.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from   w w  w. java2  s.c  om
    var d = new Date();
    d.setUTCSeconds(35, 825);
    var s = d.getUTCSeconds();
    var ms = d.getUTCMilliseconds();
    var x = document.getElementById("demo");
    x.innerHTML = s + ":" + ms;
}
</script>

</body>
</html>

Related Tutorials