简体   繁体   中英

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; substracting instead of adding hours. I expect it to change to 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?

The Datetime data type stores a date and a time. For example:

October 10th, 2021 at 10:26pm

This is neither a local time nor a UTC time... it is merely a time specifier. 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.

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.

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.

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.

To prove to yourself... visit:

https://time.is/UTC+1

and

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". Then visit the second link and say "This would be that same time in UTC". You will see that UTC+1 is one hour ahead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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