[英]How to convert Firestore Timestamp UTC to UTC+1 in React-Native using Moment?
I want to use MomentJs to convert Firestore Timestamp (which is by Default UTC) to UTC+1.我想使用 MomentJs 将 Firestore 时间戳(默认为 UTC)转换为 UTC+1。 How can I do that?
我怎样才能做到这一点?
firestore.Timestamp.now().toDate()
PS I dont want to use the local/device's time. PS我不想使用本地/设备的时间。
Firestore Timestamp (which is by Default UTC)
Firestore 时间戳(默认为 UTC)
There is no "default" really.真的没有“默认”。 When you have a Timestamp object (or a JavaScript Date , or any other native date object from a modern operating system), the moment in time is always represented internally in UTC.
当您有一个 Timestamp 对象(或JavaScript Date或来自现代操作系统的任何其他本机日期对象)时,时间总是在内部以 UTC 表示。
When you call toDate()
on a timestamp, the resulting Date is still internally represented in UTC.当您在时间戳上调用
toDate()
时,生成的日期仍以 UTC 内部表示。
Don't be confused about the "default" string representation of a Date object.不要对 Date 对象的“默认”字符串表示形式感到困惑。 It will appear in the local timezone where the computer's operation system is configured.
它将出现在配置计算机操作系统的本地时区中。 But internally, it's still UTC.
但在内部,它仍然是 UTC。
If you want to format the timestamp as a string for another timezone, you can certainly do that.如果您想将时间戳格式化为另一个时区的字符串,您当然可以这样做。 momentjs has an accompanying library Moment Timezone that can help you with that.
momentjs 有一个随附的库Moment Timezone可以帮助您解决这个问题。 The momentjs library itself will not help you with timezones (other than the one provided by the local of the system where it is running), as it's generally understood that native timestamps are always UTC.
momentjs 库本身不会帮助您处理时区(除了由运行它的本地系统提供的时区),因为通常理解本机时间戳始终是 UTC。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.