ANTD倒计时不适用于特定日期

发布于 2025-01-25 11:33:25 字数 378 浏览 3 评论 0原文

我正在尝试使用与ANTD React创建特定日期的组件。这是我的代码:

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"/>
    )
}

倒计时仅显示00:00:00:00时间戳为正数时。任何帮助都将受到赞赏。谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

舞袖。长 2025-02-01 11:33:25

截止日期传递给了&lt; countdown&gt;组件必须是绝对值(从时代开始 - 1970年1月1日)。

因此,您需要仅将其更改为:

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

您可以检查此 stackblitz 参考示例。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文