setUTCSeconds(seconds)
Sets the UTC date's seconds.
Setting the seconds to a number greater than 59 also increments the minutes.
This method can also be used to set the milliseconds.
UTC time is the same as GMT time.
setUTCSeconds() |
Yes | Yes | Yes | Yes | Yes |
dateObject.setUTCSeconds(sec,millisec);
Parameter | Description |
---|---|
sec | Required. An integer representing the seconds
Expected values are 0-59, but other values are allowed: -1 will be the last second of the previous minute 60 will be the first second of the next minute |
millisec | Optional. An integer representing the milliseconds
Expected values are 0-999, but other values are allowed: -1 will be the last millisecond of the previous second 1000 will be the first millisecond of the next second |
return a number representing the number of milliseconds between the date object and midnight January 1 1970.
var myDate = new Date();
myDate.setUTCSeconds(12);
console.log(myDate.toString());
The code above generates the following result.
The following code sets both the seconds and milliseconds in UTC time.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!-- ww w. j av a2s . c o m-->
var d = new Date();
d.setUTCSeconds(31, 876);
var s = d.getUTCSeconds();
var ms = d.getUTCMilliseconds();
var x = document.getElementById("demo");
x.innerHTML = s + ":" + ms;
}
</script>
</body>
</html>
The code above is rendered as follows: