Categories
JavaScript Answers

How to set hours, minutes, seconds for Date which is in GMT with JavaScript?

Spread the love

Sometimes, we want to set hours, minutes, seconds for Date which is in GMT with JavaScript.

In this article, we’ll look at how to set hours, minutes, seconds for Date which is in GMT with JavaScript.

How to set hours, minutes, seconds for Date which is in GMT with JavaScript?

To set hours, minutes, seconds for Date which is in GMT with JavaScript, we use some date methods.

For instance, we write

const today = new Date();

const myToday = new Date(
  today.getFullYear(),
  today.getMonth(),
  today.getDate(),
  0,
  0,
  0
);

to create the today date object.

Then we create the myToday object that sets the hour, minute, and second to 0 and the rest of the values comes from today.

getFullYear returns the 4 digit year.

getMonth returns the month from 0 for January and 11 for December.

getDate returns the date of the month.

Conclusion

To set hours, minutes, seconds for Date which is in GMT with JavaScript, we use some 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.