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

Flutter客户端使用Firebase Timestamp字段报错:无getSeconds方法

解决Firebase Timestamp的getSeconds()报错问题

错误原因

新版Firebase的Timestamp类已经移除了getSeconds()方法,改为直接通过属性访问时间戳数据。

修复后的代码

final docRef = firestore.collection(usersCollection).doc(currentUID).collection(friendsCollection).doc('a6b5Ob3TqOYPHOqssype');

final returnData = await docRef.get();
final time = returnData.get('timestamp');
print('##MyApp## database test returnData: ' + time.seconds.toString());

额外说明

  • 如果需要获取包含毫秒级的完整时间戳,可使用time.millisecondsSinceEpoch
  • 如果需要微秒级时间戳,使用time.microsecondsSinceEpoch

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 03:12:00