Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • won't work; example new Date (2017, 10, 2, 1).getTime()/86400000 change hour to 2 and you get a different integer (floor) result. Commented May 9, 2023 at 23:06
  • @omu Perhaps you need to learn to test better. It does work, although rather ugly. Perhaps needs rounding to nearest second if times are to nanosecond, but other answers have same fault. I think some of the other answers are better for clarity and maintainance. Commented May 11, 2023 at 0:21
  • Math.round won't help, try it in chrome dev tools console, new Date (2017, 10, 2, 1).getTime()/86400000, using Math.round you'll get different results at hour 12 and 13 Commented May 13, 2023 at 17:05
  • @omu You are starting the bleeding obvious and I didn't say Math.round() would work: how you code it depends upon your epsilon. And saying Math.floor() doesn't work at 12 and 13 is saying that Math.floor() does work!!! So far you haven't actually included the Math.floor() code you believe doesn't work. I tested using Math.floor(), and had no problem. Please include a fully worked example using Math.floor() and give the outputs you get. Commented May 14, 2023 at 19:51
  • @omu Link to a jsbin.com (or equivalent) that demonstrates your problem. I don't work in JavaScript any more, and I am not really that keen to help you solve your problem :-) Commented May 14, 2023 at 19:58