Categories
JavaScript Answers

How to get the current minute, hour, day, week, month, year of a given millisecond time with JavaScript?

Spread the love

Sometimes, we want to get the current minute, hour, day, week, month, year of a given millisecond time with JavaScript.

In this article, we’ll look at how to get the current minute, hour, day, week, month, year of a given millisecond time with JavaScript.

How to get the current minute, hour, day, week, month, year of a given millisecond time with JavaScript?

To get the current minute, hour, day, week, month, year of a given millisecond time with JavaScript, we can use various date methods.

For instance, we write

const date = new Date();

const seconds = date.getSeconds();
const minutes = date.getMinutes();
const hour = date.getHours();

const year = date.getFullYear();
const month = date.getMonth();
const day = date.getDate();

const dayOfWeek = date.getDay();
const milliSeconds = date.getMilliseconds();

to get various parts of the date.

getSeconds gets the seconds of the minute.

getMinutes gets the minutes of the hour.

getHours gets the hours of the day.

getFullYear gets the 4 digit year.

getMonth gets the month of the date. 0 is January, 1 is February, etc.

getDay gets the day of the month.

getMilliseconds gets the number of milliseconds of the second.

Conclusion

To get the current minute, hour, day, week, month, year of a given millisecond time with JavaScript, we can use various date methods.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.