UTC.js
const
now
=
new
Date
(
)
;
console
.
log
(
now
.
getHours
(
)
)
;
console
.
log
(
now
.
getUTCHours
(
)
)
;
Running this code will print out the current hour, and the hour of the UTC timezone. If you are currently in the UTC timezone the numbers that are output from running the program above will be the same.
UTC is useful in that it provides an international time standard reference and can therefore keep your code consistent across timezones if that is applicable to what you are developing.
In this tutorial, we learned how to create an instance of the
Date
object, and use its built-in methods to access and modify components of a specific date. For a more in-depth view of dates and times in JavaScript, you can read the
Date reference on the Mozilla Developer Network
.
Knowing how to work with dates is essential for many common tasks in JavaScript, as this can enable you to do many things from setting up a repeating report to displaying dates and schedules in the correct time zone.
Jay Chang • May 11, 2018
this example
meanfredblue • August 18, 2021
I don’t think there is a setDay() method.