JavaScript Date Methods as Simple as Possible

Guide to master JavaScript date methods

Deepak Gangwar
Sep 1 · 3 min read
Image for post
Image for post
Photo by Christin Hume on Unsplash

JavaScript is not what it used to be when it first came out. It is so much better. So it makes sense that there is so much to learn.

JavaScript is a crucial part of front end development. And if you are anything like me, you don’t know where to go. Thousands of resources to choose from which just makes us anxious and not learn anything. We get stuck in tutorial hell. Some of us may even quit.

Here is something that helped me get better at the JavaScript Date methods. I hope it will help you too. If you want to know more about JavaScript functions or arrays here are the quick and simple articles.

You can use date methods to do things like making a clock(obviously), calculating age, making a sale timer, showing content at a specific time, and much more. Each of these methods use JavaScript Date object and its methods.

So without further ado, let’s begin.


Date Now

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

Date.now();//159..........

But why January 1, 1970? Because it is known as UNIX epoch or “epoch date” is the date when the time started for Unix computers. This is marked as 0. Any time since that date is calculated based on the number of seconds elapsed.


Get Time

This method is used to get time in milliseconds since January 1, 1970. The internal clock in JavaScript counts from midnight January 1, 1970.

const time = new Date().getTime();//1598.........

Get Full Year

To get the year as a four digit number (yyyy)

const year = new Date().getFullYear();//2020

Get Month

This method is used to get month as a number (0–11) so to get the correct month you need to add 1.

const month = new Date().getMonth() + 1;//8

Get Day

This method is used to get the day as a number (0–6). Remember, in JavaScript first day of the week is Sunday. That means index zero is Sunday. This is important because some countries in consider Monday to be the first day of the week.

const day = new Date().getDay();//1 if it is Monday today 

Get Hours

Get the hour as a number (0–23)

const hour = new Date().getHours();//10

Get Minutes

To get the minutes as number (0–59)

const minutes = new Date().getMinutes();//30

Get Date

Get the date as a number (1–31)

const date = new Date().getDate();//3

The Conclusion

So these were the eight JavaScript Date methods as simple as possible. This helped me in my learning journey. And I believe it will be of importance to you, too.

JavaScript can be hard, especially if you are a beginner. But some simple guides can help us reduce the anxiety we get during the learning process. If you forget some of these, give yourself some grace. Because even developers who are doing this for decades forget this and need to brush up their knowledge from time to time.

Frontend Weekly

It's really hard to keep up with all the front-end…

Deepak Gangwar

Written by

Inspiring people with Self-Improvement, Happiness, Productivity, Writing and some code. Let’s chat deepakgangwar4265@gmail.com

Frontend Weekly

It's really hard to keep up with all the front-end development news out there. Let us help you. We hand-pick interesting articles related to front-end development. You can also subscribe to our weekly newsletter at http://frontendweekly.co

Deepak Gangwar

Written by

Inspiring people with Self-Improvement, Happiness, Productivity, Writing and some code. Let’s chat deepakgangwar4265@gmail.com

Frontend Weekly

It's really hard to keep up with all the front-end development news out there. Let us help you. We hand-pick interesting articles related to front-end development. You can also subscribe to our weekly newsletter at http://frontendweekly.co

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store