I'm trying to change the timezone from UTC+0 to GMT+2. I have tried a lot but i just can't figure it out any help would be amazing
credentials = Credentials(email, wachtwoord)
acc = Account(email, credentials=credentials, autodiscover=True)
for item in acc.inbox.all().order_by('-datetime_received')[:100]:
print(item.datetime_received)
#print: 2021-13-09 11:08:31+00:00
#print expected: 2021-13-09 13:08:31+02+00
Final solution:
from datetime import datetime
import pytz
credentials = Credentials(email, password)
acc = Account(email, credentials=credentials, autodiscover=True)
tz = pytz.timezone('Europe/Amsterdam')
for item in acc.inbox.all().order_by('-datetime_received')[:100]:
dt = item.datetime_received.astimezone(tz)
print(dt)
You can use pytz to display datetime objects in different timezones.
example:
import pytz
from datetime import datetime
ts = datetime.now()
tz = pytz.timezone('Etc/GMT+2')
print(ts.astimezone(tz))