1

I've tried many methods involving pytz to change the timezone of the discord.py user.joined_at time. It's in UTC and I need it to be in EST.

What I did was

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))
Patrick Haugh
  • 59,226
  • 13
  • 88
  • 96

1 Answers1

2

Use the pytz module

from pytz import timezone

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

In this example, I've converted it into US/Pacific but you can do whichever one you want.

Tristo
  • 2,328
  • 4
  • 17
  • 28
  • I have tried that and it hasn't worked for some reason – JustANobody Sep 20 '18 at 18:55
  • Depending on how it was generated, you may have to remind the `datetime` object that it's in UTC before you can convert it `ctx.message.author.joined_at.replace(tzinfo=timezone('UTC')).astimezone(timezone('US/Eastern'))` – Patrick Haugh Sep 20 '18 at 19:05
  • @PatrickHaugh thx, the `datetime` object wasn't in UTC, so now I fixed it with `EST` – JustANobody Sep 20 '18 at 19:22