Minifycode 2021-10-03 Viewed 1.4K times Javascript

In this article, you will learn what is JavaScript Date getter methods for normal date and UTC date

 

UTC methods :

Date also has few methods that returns the data in UTC. Let’s have a look :

getUTCDate() :

This method is used to get the date in UTC format.

getUTCDay() :

Returns the day of the week as per UTC in range 0 to 6.

getUTCFullYear() :

Returns the full year as per UTC in four digit.

getUTCHours() :

Get the current hours as per UTC. This is in range 0 to 23.

getUTCMilliseconds() :

Get the current milliseconds time as per UTC. It is in range 0 to 999.

getUTCMinutes() :

Get the current minute as per UTC. It is in range 0 to 59.

getUTCMonth() :

Get the current month as per UTC in range 0 to 11.

getUTCSeconds() :

Get the seconds in UTC in the range 0 to 59.

Example :

You can run the below example to check these methods :

var date = new Date();

console.log(`Given date : ${date}`);

console.log(`getUTCDate() : ${date.getUTCDate()}`);

console.log(`getUTCDay() : ${date.getUTCDay()}`);

console.log(`getUTCFullYear() : ${date.getUTCFullYear()}`);

console.log(`getUTCHours() : ${date.getUTCHours()}`);

console.log(`getUTCMilliseconds() : ${date.getUTCMilliseconds()}`);

console.log(`getUTCMinutes() : ${date.getUTCMinutes()}`);

console.log(`getUTCMonth() : ${date.getUTCMonth()}`);

console.log(`getUTCSeconds() : ${date.getUTCSeconds()}`);

 

getDate() :

It returns the current date of the month for a date object. This value ranges from 1 to 31.

getDay() :

It returns the day in a week. It ranges from 0 to 60 is for Sunday and 6 is for Saturday.

getFullYear() :

It returns the full year, i.e. in four digits for a Date object.

getHours :

Get the current hour in 24 hour format. It is in the range from 0 to 23.

getMilliseconds() :

Return the milliseconds for the current Date object. It is in the range from 0 to 999.

getMinutes() :

Return the current minutes for the current Date object. It is in the range from 0 to 59.

getSeconds() :

Get the current seconds in the range of 0 to 59.

getMonth() :

Get the current month in the range of 0 to 11.

getTime() :

It returns the time since January 1, 1970, 00:00:00 UTC in milliseconds i.e. time passed in milliseconds starting January 1, 1970.

getTimezoneOffset() :

Returns the timezone offset for the Date object in minutes.

getYear() :

Get the current year in two or three digits format.

Example :

Let’s learn the above methods with an example :

var date = new Date();

console.log(`Given date : ${date}`);

console.log(`getDate() : ${date.getDate()}`);

console.log(`getDay() : ${date.getDay()}`);

console.log(`getFullYear() : ${date.getFullYear()}`);

console.log(`getHours() : ${date.getHours()}`);

console.log(`getMilliseconds() : ${date.getMilliseconds()}`);

console.log(`getMinutes() : ${date.getMinutes()}`);

console.log(`getMonth() : ${date.getMonth()}`);

console.log(`getSeconds() : ${date.getSeconds()}`);

console.log(`getTime() : ${date.getTime()}`);

console.log(`getTimezoneOffset() : ${date.getTimezoneOffset()}`);

console.log(`getYear() : ${date.getYear()}`);

Output :

Given date : Thu Sep 26 2019 19:23:09 GMT-0500 (Eastern Standard Time)
getDate() : 26
getDay() : 4
getFullYear() : 2019
getHours() : 19
getMilliseconds() : 920
getMinutes() : 23
getMonth() : 8
getSeconds() : 9
getTime() : 1569505989920
getTimezoneOffset() : 300
getYear() : 119

JavaScript Date getter methods for normal date and UTC date
minify code