【发布时间】:2018-03-03 07:04:59
【问题描述】:
更新:
这工作正常。但是你能告诉我为什么at: moment(10, "HH")- 和momentJs 不起作用吗?
let firstNotificationTime = new Date();
firstNotificationTime.setDate(firstNotificationTime.getDate());
firstNotificationTime.setHours(10);
firstNotificationTime.setMinutes(0);
firstNotificationTime.setSeconds(0);
this.localNotifications.schedule({
id: 1,
title: 'Due Today',
text: 'Simons Notification',
data: { mydata: 'My hidden message this is' },
at: firstNotificationTime,
});
}
旧
我需要在 Ionic 3 应用上使用本地通知。我已经关注了这个article,下面的代码工作正常。但我需要在上午 10 点触发该事件。所以我尝试了at: moment(10, "HH")。但是在运行应用程序时它会在设备上显示此错误。
未捕获的类型错误:date.getTime 不是函数 在 dateToNum (local-notification-util.js:208) 在 Object.exports.convertTrigger (local-notification-util.js:234) 在 Object.exports.convertProperties (local-notification-util.js:156) 在 Object.fn (local-notification-core.js:75) 在 local-notification-util.js:326 在 Object.callbackFromNative (cordova.js:294) 在:1:9
此代码运行良好。但是如何使用moment设置时间呢?
this.localNotifications.schedule({
id: 1,
title: 'Attention',
text: 'Simons Notification',
data: { mydata: 'My hidden message this is' },
at: new Date(new Date().getTime() + 5 * 1000)//no issues
//at: moment(10, "HH")//this shows the above error
});
【问题讨论】:
-
我能帮我把它转换成 momentJs:文档提供了帮助。阅读并尝试一下。
-
我做到了。也许您只阅读了更新部分。你能告诉我为什么这不起作用
at: moment(10, "HH")吗? @JBNizet
标签: angular typescript ionic3 momentjs localnotification