The setMilliseconds
function in JavaSript is a method of the Date
class with the following syntax:
setMilliseconds(millisecondsValue)
millisecondsValue
: an integer value between 0 and 999setMilliseconds
returns the number of milliseconds from 1 1 January 1970 00:00:00 UTC to the updated timeThe setMilliseconds
function is called on a Date
object which results in the millisecond value of the date being updated to the millisecondsValue
.
The following code demonstrates the usage of the setMilliseconds
function:
let x = new Date('June 29, 2021 15:39:05:32');console.log(x.getMilliseconds());x.setMilliseconds(99);console.log(x.getMilliseconds());
In the example above, the Date
object x
has the date June 29, 2021 15:39:05:32
, where the millisecond’s value is 32
. After calling the setMilliseconds
function on x
, the value becomes 99
and is passed to the setMilliseconds
function.
Free Resources