Date object get methods in javascript

In this article we will learn all possible get methods of date object.

Before proceed further we should know about GMT and UTC. Every country have their own time. some have earlier and some have older from each other. But to calculate these differences we use mean solar time standard. which remains same for entire world. Every country applies + and - rules over solar time standard to get their own country time. Prior to 1972,mean solar time was called Greenwich Mean Time (GMT). But is now called as Coordinated Universal Time or Universal Time Coordinated (UTC) or Universal Standard Time .

1) getFullYear:

getFullYear method returns the year of a date as a four digit number (xxxx)

var d = new Date(2019, 05, 17, 20, 45); document.write(d.getFullYear());

OUTPUT: 2019

2) getMonth:

getMonth method returns the month of a date as a number (0-11)

var d = new Date(2019, 05, 17, 20, 45); document.write(d.getMonth());

OUTPUT: 5

3) getDate:

getDate method returns the day of a date as a number (1-31)

var d = new Date(2019, 05, 17, 20, 45); document.write(d.getDate());

OUTPUT: 17

4) getDay:

getDay method returns the weekday of a date as a number (0-6)

var d = new Date(2019, 05, 17, 20, 45); document.write(d.getDay());

OUTPUT: 1

5) getHours:

getHours method returns the hours of a date as a number (0-23)

var d = new Date(2019, 05, 17, 20, 45); document.write(d.getHours());

OUTPUT: 20

6) getMinutes:

getMinutes method returns the minutes of a date as a number (0-59)

var d = new Date(2019, 05, 17, 20, 45); document.write(d.getMinutes());

OUTPUT: 45

7) getSeconds:

getSeconds method returns the seconds of a date as a number (0-59)

var d = new Date(2019, 05, 17, 20, 45); document.write(d.getSeconds());

OUTPUT: 50

8) getMilliseconds:

getMilliseconds method returns the milliseconds of a date as a number (0-999)

var d = new Date(2019, 05, 17, 20, 45); document.write(d.getMilliseconds());

OUTPUT: 000

9) getTime:

getTime method returns the number of milliseconds since January 1, 1970

var d = new Date(2019, 05, 17, 20, 45); document.write(d.getTime());

OUTPUT: 1560784500000

10) Date.now():

now method returns the current number of milliseconds since January 1, 1970

var d = new Date(2019, 05, 17, 20, 45); document.write(Date.now());

OUTPUT: 1561022222117

11) getUTCFullYear:

getUTCFullYear method returns the UTC year of a date as a four digit number (xxxx)

var d = new Date(2019, 05, 17, 20, 45); document.write(d.getUTCFullYear());

OUTPUT: 2019

12) getUTCMonth:

getUTCMonth method returns the UTC month of a date as a number (0-11)

var d = new Date(2019, 05, 17, 20, 45); document.write(d.getUTCMonth());

OUTPUT: 5

13) getUTCDate:

getUTCDate method returns the UTC day of a date as a number (1-31)

var d = new Date(2019, 05, 17, 20, 45); document.write(d.getUTCDate());

OUTPUT: 17

14) getUTCDay:

getUTCDay method returns the UTC weekday of a date as a number (0-6)

var d = new Date(2019, 05, 17, 20, 45); document.write(d.getUTCDay());

OUTPUT: 1

15) getUTCHours:

getUTCHours method returns the UTC hours of a date as a number (0-23)

var d = new Date(2019, 05, 17, 20, 45); document.write(d.getUTCHours());

OUTPUT: 15

16) getUTCMinutes:

getUTCMinutes method returns the UTC minutes of a date as a number (0-59)

var d = new Date(2019, 05, 17, 20, 45); document.write(d.getUTCMinutes());

OUTPUT: 15

17) getUTCSeconds:

getUTCSeconds method returns the UTC seconds of a date as a number (0-59)

var d = new Date(2019, 05, 17, 20, 45); document.write(d.getUTCSeconds());

OUTPUT: 0

18) getUTCMilliseconds:

getUTCMilliseconds method returns the UTC milliseconds of a date as a number (0-999)

var d = new Date(2019, 05, 17, 20, 45); document.write(d.getUTCMilliseconds());

OUTPUT: 000

If you have any query or question or topic on which, we might have to write an article for your interest or any kind of suggestion regarding this post, Just feel free to write us, by hit add comment button below or contact via Contact Us form.


Your feedback and suggestions will be highly appreciated. Also try to leave comments from your valid verified email account, so that we can respond you quickly.

 
 

{{c.Content}}

Comment By: {{c.Author}}  On:   {{c.CreatedDate|date:'dd/MM/yyyy'}} / Reply


Categories