【问题标题】:How to set date in react native push notification?如何在反应原生推送通知中设置日期?
【发布时间】:2020-01-13 10:18:29
【问题描述】:

我正在使用 react 原生推送通知。

但是当我尝试推送本地日程时,通知不会按预期显示。它总是在我重新加载应用程序时显示(与 PushNotification.localNotification

相同的行为

如何在 PushNotification.localNotificationSchedule 中设置参数的日期?我很困惑在那里设定价值。我已经在使用时间戳,但看起来值不同。

1578909865373 => 使用 date.now

1578907260 => 我从字符串日期转换为时间戳

我的代码:

   function toTimestamp(strDate){
    var datum = Date.parse(strDate);
    return datum/1000;
   }

   const dated= toTimestamp('01/13/2020 16:21:00');

    PushNotification.localNotificationSchedule({
        //... You can use all the options from localNotifications
        message: "testing notification", // (required)
        date:  date: new Date(dated)  // in 60 secs
        // date: new Date("2020/01/13")
      });
    }

请帮助如何插入或转换正确的日期值。

谢谢

【问题讨论】:

    标签: react-native android-notifications react-native-push-notification


    【解决方案1】:

    原来我不必除以 1000 时间戳是毫秒。

    所以正确的功能是

    function toTimestamp(strDate){
    var datum = Date.parse(strDate);
    return datum;
    }
    

    【讨论】:

      猜你喜欢
      • 2016-05-29
      • 2018-01-17
      • 2017-12-18
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 2020-05-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多