简体   繁体   English

谷歌云平台如何管理时区?

[英]How Google cloud platform manages timezones?

I have a database in which I don't know which timezone the times are stored.我有一个数据库,我不知道时间存储在哪个时区。 But I need to know this because I need to generate reports in certain given time zones.但我需要知道这一点,因为我需要在特定的时区生成报告。

select INVOICE_DATE, timestamp(INVOICE_DATE), timestamp(INVOICE_DATE, "UTC+1"),  CURRENT_TIMESTAMP(), TIMESTAMP(DATETIME (INVOICE_DATE), "UTC-2")
FROM `SALES` s
limit 1000;

Whatever Invoice date I have, say today 13:00, when I use UTC+1 it turns it into 12:00;无论我有什么发票日期,比如今天 13:00,当我使用 UTC+1 时,它会变成 12:00; substracting instead of adding hours.减去而不是增加小时数。 I expect it to change to 14:00.我预计它会更改为 14:00。

SO I have two main questions.所以我有两个主要问题。

how can I know which timezone are my times stored?我怎么知道我的时间存储在哪个时区? How can I change the timezones of a given record to match the desired timezone, for example GTM-4?如何更改给定记录的时区以匹配所需的时区,例如 GTM-4?

The Datetime data type stores a date and a time. Datetime 数据类型存储日期和时间。 For example:例如:

October 10th, 2021 at 10:26pm 2021 年 10 月 10 日晚上 10:26

This is neither a local time nor a UTC time... it is merely a time specifier.这既不是本地时间也不是 UTC 时间……它只是一个时间说明符。 If you do not know what timezone the data was saved in then you can't specify it as a specific point in absolute time.如果您不知道数据保存在哪个时区,则无法将其指定为绝对时间的特定点。 When comparing to absolute times, it assumes that the Datetime is UTC.与绝对时间进行比较时,它假定日期时间为 UTC。

So... if my value contains "2021-10-10T22:26:00" and now is UTC 2021-10-10T22:26:00 then if I subtract now-value, the answer is 0.所以...如果我的值包含“2021-10-10T22:26:00”并且现在是 UTC 2021-10-10T22:26:00 那么如果我减去现在值,答案就是 0。

And... if my value contains "2021-10-10T22:26:00" and now is UTC+1 2021-10-10T22:26:00 then if I subtract now-value, the answer is 1 hour.并且...如果我的值包含“2021-10-10T22:26:00”并且现在是 UTC+1 2021-10-10T22:26:00 那么如果我减去现在值,答案是 1 小时。

In your example, if your current value is 13:00 and you create a timestamp value that is "2021-10-10T13:00:00" and say that THIS is to be interpreted as UTC+1... the you are saying that you are ONE HOUR ahead of UTC and that the time (UTC) would indeed be 12:00.在您的示例中,如果您的当前值为 13:00,并且您创建了一个时间戳值“2021-10-10T13:00:00”,并说这将被解释为 UTC+1...您说的您比 UTC 早一小时,并且时间 (UTC) 确实是 12:00。

To prove to yourself... visit:要向自己证明...请访问:

https://time.is/UTC+1 https://time.is/UTC+1

and

https://time.is/UTC https://time.is/UTC

For the first link, look at the time shown and say "This is what I would see on my wall clock if I were in timezone UTC+1".对于第一个链接,请查看显示的时间并说“如果我在时区 UTC+1,这就是我在挂钟上看到的时间”。 Then visit the second link and say "This would be that same time in UTC".然后访问第二个链接并说“这将是 UTC 的同一时间”。 You will see that UTC+1 is one hour ahead.您会看到 UTC+1 提前一小时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM