【问题标题】:See how many time remains for an event using MomentJS使用 MomentJS 查看事件还剩多少时间
【发布时间】:2020-09-28 19:04:36
【问题描述】:

我正在尝试确定距离活动开始还有多长时间。例如,如果我的活动安排在明天晚上 7:30,我想打印活动开始的剩余时间(以小时和分钟为单位)。

到目前为止,我所拥有的是这样的,我确定事件日期是否在当前日期之后:

const { eventDayFinish, eventHourFinish } = this.state;

const currentDate = moment().format();
const dateEvent = moment(`${eventDayFinish} ${eventHourFinish}`, 'YYYY-MM-DD HH:mm a').format();

const after = moment(dateEvent).isAfter(currentDate);

【问题讨论】:

标签: reactjs react-native momentjs


【解决方案1】:

您可以使用momentjs difference 计算两个日期之间的差异。

但是,check the status of moment.js project - 不建议再使用这个库了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-13
    • 1970-01-01
    • 2011-07-08
    • 2017-01-11
    • 2014-08-14
    相关资源
    最近更新 更多