Home > Mobile >  Antd Countdown not working for a specific date
Antd Countdown not working for a specific date

Time:05-02

I’m trying to create a component to a specific date using react with antd. Here's my code:

import { Statistic, Col, Row } from 'antd';

const { Countdown } = Statistic;
const deadline = Date.parse('2022-12-31') - Date.now();

const Count = () => {
    return (
        <Countdown title="Countdown" value={deadline} format="DD:HH:mm:ss"/>
    )
}

The countdown just displays 00:00:00:00 when the timestamp has is a positive number. Any help is appreciated. Thanks!

CodePudding user response:

The deadline passed to the <Countdown> component must be an absolute value (that is starting from epoch - Jan 1, 1970).

So you need to change it simply to:

const deadline = Date.parse('2022-12-31');

You can check this Stackblitz example for reference.

  • Related