This method is particularly useful when it’s necessary to retrieve the year component of a date regardless of the time zone or local system settings. It ensures consistent results regardless of the user’s geographical location.
const date = new Date(); result = date.getUTCFullYear();
Date object is used for working with dates and times. The object provides a way to create, manipulate, and format dates in various formats.
Date object can be created by declaring a new variable with the
new Date() constructor.
Consider the following example that demonstrates the usage of the
const date = new Date('2023-06-06T10:30:00Z');const year = date.getUTCFullYear();console.log(year);
This example results in the following output: