DEV Community

loading...

Ways to get a DATE 😉

Rupak Dey
Web Dev | React | Python
・1 min read

...in JAVASCRIPT 😂

Save for later.


1. Date.now()

Date.now()
Enter fullscreen mode Exit fullscreen mode

This method returns the number of milliseconds elapsed since Jan 1, 1970 00:00:00 UTC.


2. getFullYear()

new Date().getFullYear()
Enter fullscreen mode Exit fullscreen mode

Get the year as a 4 digit number (yyyy).


3. getMonth()

new Date().getMonth() + 1
Enter fullscreen mode Exit fullscreen mode

Get month as a number (0-11).


4. getDay()

const day = new Date().getDay()
const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thurs', 'Fri', 'Sat']
console.log(days[day])
Enter fullscreen mode Exit fullscreen mode

Get weekday as a number (0-6).


5. getDate() 💕😎

new Date().getDate()
Enter fullscreen mode Exit fullscreen mode

Get the day as a number (1-31).


Hope you find one soon! 😁


P.S. Want the next post to be something specific? Do let me know in the comments.

🤘🏻

Discussion (1)

Collapse
barelyhuman profile image
Reaper

people looking to handle simple date formatting should checkout github.com/lukeed/tinydate by Luke , found it a week ago