代码之家  ›  专栏  ›  技术社区  ›  El Dude

Python日期与时区,UTC和CET之间的奇怪差异

  •  1
  • El Dude  · 技术社区  · 5 年前

    示例代码

    from datetime import datetime, timezone
    import pytz
    
    tzstring = 'Europe/Berlin'
    t1 = datetime(2016, 6, 16, 2, 0, tzinfo=pytz.timezone(tzstring))
    t2 = datetime(2016, 6, 16, 2, 0, tzinfo=timezone.utc).astimezone(pytz.timezone(tzstring))
    

    观察

    print(t1): 2016-06-16 02:00:00+00:53
    print(t2): 2016-06-16 04:00:00+02:00
    

    预期

    print(t1): 2016-06-16 04:00:00+02:00  # does not match expectation
    print(t2): 2016-06-16 04:00:00+02:00  # matches expectation
    

    问题

    谁能给我解释一下吗?

    其他问题:

    0 回复  |  直到 8 年前
    推荐文章