update
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
'use client';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { parse } from 'date-fns';
|
||||
|
||||
interface CountDownProps {
|
||||
deadline: Date | string;
|
||||
deadline: number | string;
|
||||
}
|
||||
|
||||
const CounDown: React.FC<CountDownProps> = ({ deadline }) => {
|
||||
@@ -13,8 +14,10 @@ const CounDown: React.FC<CountDownProps> = ({ deadline }) => {
|
||||
|
||||
const getTime = () => {
|
||||
let time: number;
|
||||
if (deadline instanceof Date) {
|
||||
time = deadline.getTime() - Date.now();
|
||||
|
||||
if (typeof deadline == 'string') {
|
||||
const parsed = parse(deadline as string, 'dd-MM-yyyy, h:mm a', new Date());
|
||||
time = parsed.getTime() - Date.now();
|
||||
} else {
|
||||
time = Number(deadline) * 1000 - Date.now();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user