如何比较Firebase时间戳? [英] How to compare firebase timestamps?

查看:57
本文介绍了如何比较Firebase时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的云功能代码:

I have cloud function code code like this:

console.log(`ts: ${(element.get('expire') as admin.firestore.Timestamp).toDate().toUTCString()} now: ${admin.firestore.Timestamp.now().toDate().toUTCString()}`)
const greater = (element.get('expire') as admin.firestore.Timestamp) > admin.firestore.Timestamp.now()
const lower = (element.get('expire') as admin.firestore.Timestamp) < admin.firestore.Timestamp.now()
console.log(`greater: ${greater} lower: ${lower}`)

在控制台中:

ts:2019年4月8日星期一20:59:59 GMT现在:2019年3月8日星期五20:19:18 GMT

ts: Mon, 08 Apr 2019 20:59:59 GMT now: Fri, 08 Mar 2019 20:19:18 GMT

更大:错误更低:错误

那么与时间戳比较如何呢?

So how correctly compare to Timestamps?

推荐答案

您可以通过比较纳秒属性.或者,为了简化起见,并且不需要纳秒级的精度,您只需比较其

You can do this by comparing the seconds and nanoseconds properties on the Timestamp objects. Or, to make it simpler, and you don't need nanosecond precision, you can just compare the results of the results of their toMillis() values.

这篇关于如何比较Firebase时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆