You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Appsmith应用中或通过JSON向Firebase存储Timestamp格式时间戳

在Appsmith中向Firestore写入Timestamp类型字段的方法

Firestore的Timestamp是专属数据类型,直接通过普通JSON传入日期字符串、毫秒时间戳都会被识别为基础的字符串/数字类型,需要按照Firestore要求的格式传参才能正确生成Timestamp类型字段。

场景1:存储Firebase服务端当前时间

直接在请求的对应字段中使用Firebase官方的时间标记即可,服务端会自动解析为当前Timestamp:

// 拼REST请求时的写法
{
  "fields": {
    "createTime": {
      "timestampValue": {".sv": "timestamp"}
    }
  }
}

如果使用Appsmith内置的Firestore查询模板,直接写入标记对象即可:

{
  createTime: firebase.firestore.FieldValue.serverTimestamp()
}

场景2:存储Appsmith DatePicker选择的自定义时间

  • 方式1:手动拼Firestore REST请求结构
    将DatePicker选中的时间转为ISO8601格式,放入timestampValue字段中:
{
  "fields": {
    "eventTime": {
      "timestampValue": "{{datePicker1.selectedDate.toISOString()}}"
    }
  }
}
  • 方式2:使用Appsmith内置Firestore连接器(推荐)
    Appsmith的Firebase官方连接器会自动识别JS日期对象并转换为Timestamp类型,直接传日期对象即可:
// Firestore查询的文档数据配置
{
  eventTime: new Date(datePicker1.selectedDate),
  eventName: input1.text
}

注意:不要直接将日期字符串、毫秒时间戳赋值给字段根节点,必须按照上述结构传参,才会被Firestore识别为Timestamp类型。

内容的提问来源于stack exchange,提问作者Keshav Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.12 20:12:03