I'm trying to create a countdown using dayjs, with a unix timestamp string, but it has to be according to a specific timezone (in this case its EST), this is my current code:
//Timestamp - 1645631100000
const formattedEndTime = dayjs.utc(1645631100000).format();
const total =
Date.parse(formattedEndTime) -
Date.parse(dayjs().tz("America/New_York").format());
const seconds = Math.floor((total / 1000) % 60);
const minutes = Math.floor((total / 1000 / 60) % 60);
const hours = Math.floor((total / (1000 * 60 * 60)) % 24);
const days = Math.floor(total / (1000 * 60 * 60 * 24));
return {
total,
days,
hours,
minutes,
seconds,
};
It is not giving me the right result, its always a few hours off, would appreciate any help with this, thanks!