I want to convert the "from" date object starting from 00:00:01 and "to" date object ending with 23:59:59. How do i do that. Here’s my code.
let from = new Date(req.params.from);
let to = new Date(req.params.to);
console.log('from: ',from,'to: ',to)
result of console:
from: 2024-01-25T00:00:00.000Z to: 2024-01-25T00:00:00.000Z
I tried this method:
from.setHours(0,0,0,1);
to.setHours(23,59,59,999)
its result was:
2024-01-24T18:30:00.001Z 2024-01-25T18:29:59.999Z
Here hour stamp starts with 18 and ends in 06
2
Answers
Here is a possible solution.
I do not know if you are aware of how setHours works.
Here is a simple description:
When you create a Date object using a string like ‘2024-01-25T00:00:00.000Z’, it is automatically interpreted as being in UTC (Coordinated Universal Time). However, when you use the setHours method, it adjusts the time based on your local time zone.
This is how you would achieve this.
and the output is:
I tried to run this code:
and i got this output
Which looks to me like what you expected.