0

Let's say I have an epoch value 1665531785000 which converts to "Tuesday, October 11, 2022 11:43:05 PM" in human readable format.

How can we modify 1665531785000 to 1665532800000 which converts to "Wednesday, October 12, 2022 12:00:00 AM"(set the value to 12AM next day) in javascript/typescript

  • Does this answer your question? [How to get start and end of day in Javascript?](https://stackoverflow.com/questions/8636617/how-to-get-start-and-end-of-day-in-javascript) – Souperman Nov 02 '22 at 05:20

2 Answers2

0

Doing complex date math is something you probably want to use a library for. There are a handful of options, but for example luxon is a library that could be used for this:

import { DateTime } from 'luxon';
DateTime.fromJSDate(new Date(1665531785000))
  .plus({ day: 1 })
  .startOf('day')
  .toJSDate();
Souperman
  • 5,057
  • 1
  • 14
  • 39
0

As of your example, I assume you would like to use UTC. You can do it without any additional libraries as below.

let d = new Date(1665531785000);
d.setUTCDate(d.getUTCDate() + 1);
d.setUTCHours(0, 0, 0);
const e = d.valueOf();

console.log(e);
N.F.
  • 3,844
  • 3
  • 22
  • 53