Languages
[Edit]
EN

JavaScript - Date get methods

3 points
Created by:
JoanneSenior
1070

In this article, we would like to describe methods thet can be used to get information from Date object in JavaScript.

MethodDescription
getDate()Gets the day number in the month (from 1 to 31 depemening on month)
getMonth()

Gets the month index number (from 0 (January) to 11 (December))

Check: JavaScript - English month names article.

getFullYear()Gets the year number (format: YYYY)
getHours()Gets the hours (from 0 to 23)
getMinutes()Gets the minutes (from 0 to 59)
getSeconds()Gets the seconds (from 0 to 59)
getMilliseconds()Gets the milliseconds (fomr 0 to 999)
getDay()

Gets the weekday index number (from 0 (Sunday) to 6 (Saturday))

Check: JavaScript - English day names article.

getTime()Gets the time in milliseconds since Unix Epoch (January 1, 1970)
Static MethodDescription
Date.now()

Gets the current time in milliseconds since Unix Epoch (January 1, 1970)

Note: this method was added in ES5.

Note:

The Date.now() is equivalent to getTime(), however you should use Date.now() since it is faster.

 

Practical example

Edit

In this section, we present mentioned methods.

Note:

The hours in ISO format may be different depending on the time zone you live in. My time is currently given in GMT+0200 (Central European Summer Time), that's why ISO format adds 2 hours (from 15 to 17).

Note:

To see the difference between Date.now() and getTime() go to the article from See also section.

 

See also

Edit
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join