首页 > 解决方案 > Firebase 规则中的当前年份

问题描述

我需要 2019 年作为当年,如果有的话,这些 Firebase 规则中当年的变量是什么?

我的 Firebase 规则:

{
  /* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */
  "rules": {
    ".read": false,
    ".write": false,
    "statistics": {
      "2019": {
        "total": {
        ".read": true
        }
      }
    }
  }
}

标签: firebasefirebase-realtime-databasefirebase-security

解决方案


本年度无变量。now自 unix 纪元以来,有一个以毫秒为单位调用当前时间的变量。你可以从那个时候得出年份。如果您使用诸如此类的网络工具unix 时间查找 2019 年的开始和结束,您会发现开始是 1546300800,结束是 1577836800。但那是如果您的时区是 UTC,这可能不是您的想。因此,您必须具体说明您认为 2019 年对您的应用用户而言何时开始和结束。


推荐阅读