在Flutter中保存到Firestore中之前,如何将DateTime转换为Timestamp? [英] How to convert DateTime to Timestamp before saving in Firestore in Flutter?

查看:59
本文介绍了在Flutter中保存到Firestore中之前,如何将DateTime转换为Timestamp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从datePicker中选择了日期",并希望将该日期(类型为DateTime)保存为Firestamp类型的Firestore.我使用了Firestore.fromDate(date),但它将数据存储在Firestore中作为地图(纳秒,秒).

I picked a "date" form datePicker and wanted to save that date (type as DateTime) to Firestore in Timestamp type. I used Firestore.fromDate(date) but it stores data in Firestore as a map(nanoseconds, seconds).

推荐答案

将Firebase Timestamp 类用作:

Use the Firebase Timestamp class as:

Timestamp.fromMicrosecondsSinceEpoch(myDateTime.microsecondsSinceEpoch)

还有许多其他的构造函数,请看一下文档.

There are many other constructors, take a look at the docs.

这篇关于在Flutter中保存到Firestore中之前,如何将DateTime转换为Timestamp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆