Android通知负载中的FCM,事件时间

3
我想让通知在运行此HTTP函数后大约5分钟后推送。 从通知的JSON中删除event_time,则我将收到具有现在时间轴的推送通知,但如果我硬编码event_time,则时间会显示50年前自纪元时间,即使我将年份设为999,它也只增加2年。我完全不明白。然后在Google和Firebase中找到了Timestapm格式,因此使用它,并且Android在解析JSON有效载荷时出错,称找不到某个字段。您有任何想法来格式化Zulu RC399时间格式吗?

pp.get('/sendCloudMessageReminderActivation', async (req, res) => {
    const x = req.query.userUID;
    const xstr = String(x);
    const zxcv = admin.firestore().collection('user').doc(xstr);
    const xoxo = await zxcv.get();
    var today = new Date();
    // today.setHours(today.getHours()+1);
    today.setHours(today.getHours()+8);
    // today.setFullYear(today.getFullYear()+50);
    var xoxocode;
    console.log(today+'saya saya sebelum cagbge');

    // today =  ISODateString(today);
    const timestamp = admin.firestore.Timestamp.fromDate(today);
    console.log(timestamp.nanoseconds +'siniiiiiiiiiiiiiiiiiiiii');






    if (xoxo!==null) {

        xoxocode= await xoxo.data().cloudMessagingToken;
        const message = {
            notification: {
                title: 'your account is still in active state',
                body: 'Tap here to check it out!'
            },
            android:{
                priority:'high',
                // important : 'MAX',
                notification:{
                    notification_priority: "PRIORITY_MAX",
                    event_time: timestamp,// when ever i cahnge this event use ZULU RC339 format i still give my 50 year ago notification. i did my research but cant figure out how to do this ,
                    default_sound: true,

                    // notification_priority: PRIORITY_MAX
                }
            },
            token: xoxocode
          };


        // res.status(200).send('authorized');

        const respondfrommesage = admin.messaging().send(message);
        console.log(respondfrommesage);


        res.status(200).send('message send notification');


    }

    res.end();


  });

你解决了这个问题吗? - Mindaugas Varkalys
不,我没有做这个功能,因为它只是我的毕业设计项目,时间有限,但将来会重新使用这个FMC功能。 - Epool Ranggi
我向Firebase报告了这个问题,他们复现了它并计划修复它,但他们无法提供任何时间表。 - Mindaugas Varkalys
1个回答

1

Zulu不是时间格式,而是一个时区。Zulu只是UTC的另一个名称。

根据这个文章:

UTC时间的另一个名称是“Zulu”或“Z时间”。

现在,关于时间戳值。如果您创建一个Date对象并使用日期的毫秒纳秒属性,则它将始终以相应属性类型(毫秒/纳秒)给出差异,

从您创建实例的时间和UNIX开始时间,即1970年1月1日

截至2020年1月1日,已经过去了50年。因此,event_time中有50年的差异。

如果您有任何其他疑问,请告诉我。


好的,我犯了一个错误,关于Zulu时区的问题,我刚刚了解到Zulu采用0000时间格式,而我使用马来西亚或新加坡的0080时间格式,但在even_time字段中, 我也尝试过:event_time: "2020-01-01T23:00:00Z",但仍然得到了1970年1月19日的结果,Android实际上是如何计算的呢? - Epool Ranggi
我在使用Python的Firebase Admin和从Google Playground发送通知时遇到了相同的问题。我认为这可能是一个Android的问题。 - Cătălin Florescu

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接