python - 更改joined_at时区discord.py

标签 python python-3.x datetime timezone discord.py

我尝试了许多涉及pytz的方法来更改discord.py user.joined_at时间的时区。它是 UTC,我需要它是 EST。

我所做的是

eastern = timezone('US/Eastern')
eastern.zone
fmt='%#c
jointime=eastern.localize(datetime(user.joined_at))
createtime=eastern.localize(datetime(user.created_at))
embed=discord.Embed(title='User Information:', color=0x0000ff)
embed.set_author(name='{0.name}'.format(user),icon_url='{0.avatar_url}'.format(user))
embed.add_field(name='Join Date:', value='{0.name} joined on'.format(user)+jointime.strftime(fmt))
embed.add_field(name='Account Creation:', value='{0.name}\'s account was created on '.format(user)+createtime.strftime(fmt))

最佳答案

使用 pytz 模块

from pytz import timezone

current_timezone_time = ctx.message.author.joined_at
new_timezone_time = current_timezone_time.astimezone(timezone('US/Pacific'))
#do whatever

在此示例中,我已将其转换为 US/Pacific 但您可以执行 whichever one you want .

关于python - 更改joined_at时区discord.py,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52428769/

相关文章:

mysql - 为什么我在一种情况下进行了全表扫描,而在另一种情况下却没有?

python - 扫描数据帧的行以获取特定值

python-3.x - 使用ffmpeg从MP4文件中仅提取Y(YUV420p)帧?

python - 我可以在不转换相关数据的情况下在 matplotlib 中模拟轴的对数刻度吗?

Python __call__() 这是一个隐式类方法吗?

r - 确定哪个id的时间点早于R中的另一个时间点

python - 如何为pymc3模型中的参数添加约束?

python - CherryPy、线程和成员变量;潜在的问题?

python - 如何在不编译任何东西的情况下在 Ubuntu 18.04 LTS 上安装 Python 3.5.x

JavaScript/Extjs - 根据时间戳计算小时数