【发布时间】:2022-06-11 00:13:17
【问题描述】:
我的 Cloud Firestore 有 TimeStamp 数据,我正在获取它并将其显示在数据表小部件中。为了将其转换为所需的日期格式,我使用了DateFormat('yMd').Format()。但是format() 只接受日期时间而不接受时间戳。因此,为了将 firebase 时间戳数据转换为日期时间,我使用了TimeStamp().toDate()。但是TimeStamp() 接受秒和纳秒。我尝试以这种格式提供 Firebase 时间戳数据 data['paidDate'] 我得到错误,我该如何解决这个问题。
return Center(
child: Container(
child: DataTable(
columns: const [
DataColumn(label: Text('Amount')),
DataColumn(label: Text('Paid Date'))
],
rows: snapshot.data!.docs.map((data) {
// DateTime datee = data['paidDate'];
return DataRow(cells: [
DataCell(Text(data['amount'])),
DataCell(Text(DateFormat('yMd')
.format(Timestamp(data['paidDate']).toDate())))
]);
}).toList()),
));
【问题讨论】:
标签: flutter firebase google-cloud-firestore