【问题标题】:Save Read Unity3d c# Google Firebase ServerValue.Timestamp保存读取 Unity3d c# Google Firebase ServerValue.Timestamp
【发布时间】:2017-02-21 00:59:19
【问题描述】:

我想将 Server.Timestamp 保存到我的 Firebase 数据库 unity3d c#。我尝试了几种方法,但都没有得到结果。从 Google Firebase 示例中,我可以看到时间戳保存为长 https://firebase.google.com/docs/database/unity/structure-data 但他们的例子都没有真正处理保存这个值或读取这个值。

"chats": {
    "one": {
      "title": "Historical Tech Pioneers",
      "lastMessage": "ghopper: Relay malfunction found. Cause: moth.",
      "timestamp": 1459361875666
    },
    "two": { ... },
    "three": { ... }
  },

我找不到一个简单的例子来保存和读取 servervalue.timestamp。 基本上我想知道如何在 c# 中保存和使用 Google Firebase ServerValue.Timestamp。

谢谢。

【问题讨论】:

    标签: unity3d firebase firebase-realtime-database


    【解决方案1】:

    在您的统一应用程序中,您创建要发送的 JSON,您可以将时间戳值替换为以下内容:

    "chats": {
        "one": {
          "title": "Historical Tech Pioneers",
          "lastMessage": "ghopper: Relay malfunction found. Cause: moth.",
          "timestamp": {".sv" : "timestamp"}
        },
        "two": { ... },
        "three": { ... }
        },
    

    然后服务器会替换

    {".sv" : "timestamp"}
    

    通过

    1459361875666 // current server date
    

    您将能够将“时间戳”字段读取为长格式

    这是一个工作示例:

            Dictionary<string, object> scoreUpdate = new Dictionary<string, object> ();
            Dictionary<string, object> timestamp = new Dictionary<string, object> ();
            timestamp [".sv"] = "timestamp";
            scoreUpdate ["scores/" + userID + "/name"] = name;
            scoreUpdate ["scores/" + userID + "/score"] = -score;
            scoreUpdate ["scores/" + userID + "/time/"] = timestamp;
    
            DBRef.Root ().UpdateChildrenAsync (scoreUpdate);
    

    【讨论】:

    • 谢谢。您能否展示一个非常简单的示例,我们可以在 C# 中执行此操作。我尝试了几种方法,但保存时间不长。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-28
    • 2017-05-15
    • 1970-01-01
    • 2018-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多