我尝试了许多涉及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/