Calculate time util function added
This commit is contained in:
parent
f28671f99e
commit
4cfe3ebfaa
|
|
@ -0,0 +1,15 @@
|
||||||
|
export const calculateTimeLeft = (targetDate: string) => {
|
||||||
|
const now = new Date();
|
||||||
|
const eventDate = new Date(targetDate); // Parse target date directly
|
||||||
|
const timeDifference = eventDate.getTime() - now.getTime();
|
||||||
|
|
||||||
|
if (timeDifference <= 0) {
|
||||||
|
return { hours: 0, minutes: 0, seconds: 0 }; // Countdown finished
|
||||||
|
}
|
||||||
|
|
||||||
|
const hours = Math.floor(timeDifference / (1000 * 60 * 60));
|
||||||
|
const minutes = Math.floor((timeDifference % (1000 * 60 * 60)) / (1000 * 60));
|
||||||
|
const seconds = Math.floor((timeDifference % (1000 * 60)) / 1000);
|
||||||
|
|
||||||
|
return { hours, minutes, seconds };
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue