【问题标题】:Timestamp with timezone in relation to UTC与 UTC 相关的时区时间戳
【发布时间】:2017-06-24 22:08:35
【问题描述】:

我的数据库中有这个时区America/Sao_Paulo

例子:

2017-02-07 10:06:32.157564-02

ts = db.Column(db.DateTime(timezone=True), index=True, server_default=func.now())

我的问题是,这意味着10:06:32 已经比 UTC 少了两个小时?所以 -2 只是提供信息,这是正确的时间。

或者这意味着我们需要从 10:06:32 中减去两个小时 (-2) 才能得到 America/Sao_Paulo 时区的正确小时数?

【问题讨论】:

  • @VaoTsun 你的评论很混乱。
  • 抱歉让您感到困惑。我用例子发布了答案。希望会很清楚
  • @VaoTsun 你的意思是添加。该值为当地时间。一个反转符号以返回 UTC。
  • 是的,它肯定会反转以获得 UTC。我删除了评论,这样就不会再混淆了。谢谢!

标签: python sqlalchemy timezone utc timestamp-with-timezone


【解决方案1】:

我在 GMT+2 atm,所以为了模拟你的 tz,我将它设置为你的,然后在同一时刻选择你的时间 ATM 和 UTC 时间:

t=# set timezone TO 'America/Sao_Paulo';
SET
Time: 0.222 ms
t=# select now() sao_paulo, now() at time zone 'UTC' utc;
           sao_paulo           |            utc
-------------------------------+----------------------------
 2017-02-07 13:54:35.112992-02 | 2017-02-07 15:54:35.112992
(1 row)

Time: 0.163 ms

【讨论】:

    猜你喜欢
    • 2023-03-19
    • 1970-01-01
    • 2017-09-17
    • 1970-01-01
    • 1970-01-01
    • 2021-02-21
    • 2018-02-22
    • 1970-01-01
    • 2019-03-09
    相关资源
    最近更新 更多