Reputation: 724
I am new to momentjs and stuck with an issue. I have to clear document from mongoDB at the start of every day. Example: data has to be cleared at 2020-07-14T00:00:00:000z. I have added TTL for the same.
This is what I have added.
const date = new Date();
date.setDate(date.getDate() + 1);
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
date.setMilliseconds(0);
The problem is the pod which is running the code is in UTC time. ie; 09:00pm UTC (server pod time) -> 12.00 am Finish Time -> 02:30 am IST (My local time). Is there any way I can get the start of the day in the above mentioned format with "Europe/Helsinki" timezone, so that finish time 12.00AM in my server, document should get cleared.
Any help would be really appreciated.
Thanks in advance
Upvotes: 0
Views: 587
Reputation: 23768
If you want your app to be operated at a time which is in another time zone than what you have in the server, you need to offset the time by the hours which makes the difference between your server time and the local time.
For example, the EUST (Europe/Helsinki) is +3GMT. You need to add this offset to the comparison equation if you want the operation to be aligned with your local time.
const offsetEUST = 3;
const date = new Date();
date.setDate(date.getDate() + 1);
date.setHours(0 + offsetEUST );
date.setMinutes(0);
date.setSeconds(0);
date.setMilliseconds(0);
Upvotes: 1