Python 在时区discord.py更改加入的\u
我尝试了许多方法,包括Python 在时区discord.py更改加入的\u,python,python-3.x,datetime,timezone,discord.py,Python,Python 3.x,Datetime,Timezone,Discord.py,我尝试了许多方法,包括pytz来更改discord.py用户的时区。在时间加入了\u。它在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(titl
pytz
来更改discord.py用户的时区。在时间加入了\u。它在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
,但您可以这样做。我已经尝试过,但由于某些原因,它不起作用。根据它的生成方式,您可能必须提醒datetime
对象它在UTC中,然后才能转换它ctx.message.author.joined\u at.replace(tzinfo=timezone('UTC')).astimezone(timezone('US/Eastern'))
@PatrickHaugh-thx,datetime
对象不是UTC,所以现在我用EST