0

I am trying to get the value of next week ( + 7 days) at 09:00. I can get the Date using

 new Date().setDate(new Date().getDate() + 7)

For example, it returns: 1619343639426

which translates to

new Date(1619343639426)
Sun Apr 25 2021 15:10:39 GMT+0530 (India Standard Time)

I want to get the value for Sun Apr 25 2021 09:00:00 GMT+0530 (India Standard Time)

how to do that ?

Samuel
  • 1,128
  • 4
  • 14
  • 34
  • 1
    Does this answer your question? [Add days to JavaScript Date](https://stackoverflow.com/questions/563406/add-days-to-javascript-date) – Christopher Apr 18 '21 at 09:48
  • @Christopher: I want to jump to specific time of next week. I can jump 7 days but I want to be at `09:00` – Samuel Apr 18 '21 at 09:51
  • 2
    To set the time for a date to 9am you can use [`date.setHours(9, 0, 0, 0);`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours). – Mady Daby Apr 18 '21 at 09:51
  • See here https://stackoverflow.com/questions/563406/add-days-to-javascript-date – smartdroid Apr 18 '21 at 09:54

1 Answers1

2

Try

new Date(new Date().setDate(new Date().getDate() + 7)).setHours(9, 0, 0, 0)

Shashank Vivek
  • 16,888
  • 8
  • 62
  • 104
  • 1
    Don't forget to set the milliseconds to 0 also. It's not very efficient to create 3 separate Date object, likely it's more efficient to use `let d = new Date(); d.setDate(d.getDate() + 7); d.setHours(9,0,0,0)`. – RobG Apr 18 '21 at 12:28