JavaScript Date method: setSeconds()
[this page | pdf | back links]
The setSeconds() method (when applied to a
JavaScript
date) sets the
date variable’s second (and optionally its millisecond).
It
has the following syntax with the following parameters:
date.setSeconds(second,millisecond)
Parameter
|
Required / Optional
|
Description
|
second
|
Required
|
Integer representing seconds.
Typically, will be in range 0 – 59. However, e.g. 0 will result in last second
of previous minute, 60 will result in first second of next minute, etc.
|
millisecond
|
Optional
|
Integer representing
milliseconds. Typically, will be in range 0 – 999. However, e.g. 0 will
result in last millisecond of previous second, 1000 will result in first
millisecond of next second, etc.
|
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,th,tr,td {border: 1px solid black; border-collapse: collapse;}
</style>
</head>
<body>
<table>
<tr>
<th>Example</th>
<th>Resulting value of <code>x</code></th>
</tr>
<tr>
<td><code id="Example"></code></td>
<td><code id="Result"></code></td>
</tr>
</table>
<script>
var d = new Date(Date.now());
document.getElementById("Example").innerHTML =
'var d = new Date(Date.now());<br>' +
'var x = new Date(d.setSeconds(1)).toISOString();';
document.getElementById("Result").innerHTML =
new Date(d.setSeconds(1)).toISOString();
</script>
</body>
</html>
|
FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodDateSetSeconds() {
var d = new Date(Date.now()); return !!d.setSeconds;
} |
NAVIGATION LINKS
Contents | Prev | Next | JavaScript Dates