【问题标题】:How to get time in specific timezone in telethon event handler如何在 Telethon 事件处理程序中获取特定时区的时间
【发布时间】:2021-02-11 02:10:33
【问题描述】:

我正在使用 Telethon 库来制作电报机器人。 当我使用event.date 时,它正在打印 +00.00 时区的时间。 如何在特定时区打印时间

【问题讨论】:

  • 也许您应该使用标准模块datetime 将其转换为其他时区?

标签: python telegram telethon


【解决方案1】:

python - Convert UTC datetime string to local datetime。窃取使用python-dateutil的最佳答案:

from dateutil import tz
local_datetime = event.date.astimezone(tz.tzlocal())

【讨论】:

    【解决方案2】:
    from datetime import datetime
    print(datetime.now().isoformat(timespec='minutes'))
    

    看看datetime library

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-22
      • 1970-01-01
      • 2022-11-03
      • 2013-10-21
      • 2016-03-01
      • 1970-01-01
      相关资源
      最近更新 更多