Sometimes, we want to get the current GMT world time with JavaScript.
In this article, we’ll look at how to get the current GMT world time with JavaScript.
How to get the current GMT world time with JavaScript?
To get the current GMT world time with JavaScript, we can use the various date methods to get the date parts of the UTC equivalent of the current date and time.
For instance, we write:
const d = new Date();
console.log(d.getUTCDate())
console.log(d.getUTCDay())
console.log(d.getUTCFullYear())
console.log(d.getUTCHours())
console.log(d.getUTCMilliseconds())
console.log(d.getUTCMinutes())
console.log(d.getUTCMonth())
console.log(d.getUTCSeconds())
to call getUTCDate
to get the UTC day of the month.
getUTCDay
to get the UTC day of the week.
getUTCFullYear
to get the UTC year.
getUTCHours
to get the UTC hour.
getUTCMilliseconds
to get the UTC milliseconds.
getUTCMinutes
to get the UTC minutes.
getUTCMonth
to get the UTC month.
And getUTCSeconds
to get the UTC seconds.
Conclusion
To get the current GMT world time with JavaScript, we can use the various date methods to get the date parts of the UTC equivalent of the current date and time.