c# - 我如何将 firestore 时间戳转换为不同的格式 en c#

标签 c# firebase datetime google-cloud-firestore timestamp

我试图在 c# 中的 dateTimePicker 值中放置一个时间戳,我不知道是否可能,但我收到了一个错误。如果可能的话,我想把它放在格式(“dd/MM/yyyy”)中。

dateTimeDate.Value = student.date;
但我收到这个错误,
Cannot implicitly pass the type "Google.Cloud.firestore.Timestamp" in "System.DateTime". 
所以我尝试这个,但仍然无法正常工作。
dateTimeDate.Value = student.date.ToDateTime();
我该如何解决这个问题,我也想知道如何将其转换为字符串以放入文本框。

最佳答案

Firestore 返回 Google.Cloud.Firestore.Timestamp目的
如果我们将其转换为字符串看起来像:

Timestamp: 2021-04-03T10:34:48.865466Z


我们可以将其转换为 DateTime目的:
DateTime result = DateTime.ParseExact(TIMESTAMP.ToString().Replace("Timestamp:", "").Trim(), 
    "yyyy-MM-ddTHH:mm:ss.ffffffK", null);

关于c# - 我如何将 firestore 时间戳转换为不同的格式 en c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66448972/

相关文章:

c# - twain 还是威亚?这两个接口(interface)之间有点迷路

c# - Xamarin.Forms 使非透明覆盖不可点击

datetime - 获取当前日期的年份

python - Django 中 UpdateView 的日期格式更改

python - 给 pandas 日期列序号值

c# - 在 c# 中从 Dataview 排序后选择前 N 行

c# - Asp.net 随机停止遵守表单例份验证白名单

ios - React Native 和 Firebase 错误 403

android - Firebase 登录并使用用户名注册

php - 如何使用触发器发送 firebase 推送通知