我可以更改保存在 Firestore 时间戳字段中的时区吗? [英] can I change timezone saved in Firestore timestamp field?

查看:26
本文介绍了我可以更改保存在 Firestore 时间戳字段中的时区吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以从

如您所见,有 UTC+7.我来自印度尼西亚,我的 Firestore 数据库也在区域 asia-southeast2(印度尼西亚雅加达).

我的问题是......

我真的可以改变那个时区吗?即使文档说时间戳独立于任何时区.但我不明白为什么 Firestore 可以得到 UTC+7,这是正确的,因为我从印度尼西亚 (UTC+7) 发送数据

我尝试在我的 Android 应用程序中操作日期对象,并使用不同的时区 (UTC+9) 发送数据,但它始终会保存为 UTC+7.

所以基本上我试图找出我的代码中是否有错误或 firestore 中的时区是否无法更改

解决方案

在 Firestore 中,时区不会编码为时间戳值.所有时间戳均以 UTC 衡量.这对于所有主要操作系统的日期和时间都是正常的.您在控制台中看到的是为本地计算机当前配置的时区格式化的时间戳值.如果您想在那里看到不同的时区,则必须更改计算机的配置时区.更改时间戳值本身无济于事.

您的代码应该只创建和操作同样以 UTC 衡量的时间戳值.如果您以某种方式从另一个时区接收格式化的数据,您应该在创建时间戳之前先将其转换为 UTC.

so from the documentation in here it said that

A Timestamp represents a point in time independent of any time zone or calendar, represented as seconds and fractions of seconds at nanosecond resolution in UTC Epoch time

but here is my timestamp field in my document

as you can see, there is UTC+7. I am from Indonesia, and my Firestore database is also in region asia-southeast2 (Jakarta,Indonesia).

my question is .....

can I actually change that timezone ? even though the documentation says that timestamp is independent from any timezone. but I don't Understand why Firestore can get that UTC+7, which is correct because I send the data from Indonesia (UTC+7)

I try to manipulate date object in my Android app, and send data using different timezone (UTC+9), but it will always be saved as UTC+7.

so basically I am trying to find out if there is a bug in my code or timezone in firestore can't be changed

解决方案

In Firestore, timezones are not encoded into timestamp values. All timestamps are measured in UTC. This is normal for dates and times for all major operating system. What you see in the console is the timestamp value formatted for the timezone that your local computer is currently configured for. If you want to see a different timezone there, you would have to change your computer's configured timezone. Change the timestamp value itself won't really help.

Your code should only create and manipulate timestamp values that are also measured in UTC. If you are somehow receive data formatted form another timezone, you should convert it to UTC first before creating a timestamp.

这篇关于我可以更改保存在 Firestore 时间戳字段中的时区吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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