In this article, you will learn what is JavaScript Date getter methods for normal date and UTC date
Date also has few methods that returns the data in UTC. Let’s have a look :
This method is used to get the date in UTC format.
Returns the day of the week as per UTC in range 0 to 6.
Returns the full year as per UTC in four digit.
Get the current hours as per UTC. This is in range 0 to 23.
Get the current milliseconds time as per UTC. It is in range 0 to 999.
Get the current minute as per UTC. It is in range 0 to 59.
Get the current month as per UTC in range 0 to 11.
Get the seconds in UTC in the range 0 to 59.
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()}`);
It returns the current date of the month for a date object. This value ranges from 1 to 31.
It returns the day in a week. It ranges from 0 to 6. 0 is for Sunday and 6 is for Saturday.
It returns the full year, i.e. in four digits for a Date object.
Get the current hour in 24 hour format. It is in the range from 0 to 23.
Return the milliseconds for the current Date object. It is in the range from 0 to 999.
Return the current minutes for the current Date object. It is in the range from 0 to 59.
Get the current seconds in the range of 0 to 59.
Get the current month in the range of 0 to 11.
It returns the time since January 1, 1970, 00:00:00 UTC in milliseconds i.e. time passed in milliseconds starting January 1, 1970.
Returns the timezone offset for the Date object in minutes.
Get the current year in two or three digits format.
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()}`);
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