【问题标题】:Using pytz TImezones for discord.py为 discord.py 使用 pytz 时区
【发布时间】:2020-08-26 19:10:17
【问题描述】:

如何在Europe/Berlin 时区获取guild.created_at 时间? 我试过guild.created_at.astimezone(timezone('Europe/Berlin')),但它不起作用。我还尝试了其他论坛、教程和文档,但没有成功。

我已经看过选项了:

pytz localize vs datetime replace

http://pytz.sourceforge.net/

pytz - Converting UTC and timezone to local time

【问题讨论】:

标签: python-3.x timezone discord discord.py pytz


【解决方案1】:

你可以使用 fromutc 函数:

pytz.timezone('Europe/Berlin').fromutc(guild.created_at)

【讨论】:

  • pytz.timezone('Europe/Berlin').fromutc(guild.created_at) NameError: name 'pytz' is not defined
  • 你需要像以前一样导入 pytz 包。
  • timezone('Europe/Berlin').fromutc(guild.created_at) 在我的案例中有效
猜你喜欢
  • 2018-01-03
  • 2018-09-05
  • 2012-08-29
  • 2013-08-30
  • 2015-10-12
  • 2015-02-24
  • 2022-01-11
  • 2019-04-06
  • 2015-06-13
相关资源
最近更新 更多