0

I am using exchangelib to process emails in python. When I execute the following code,Iget UTC datetime.How can I get the local date and time of the emails received as per the local timezone?

for email_message in outlook_inbox:  #outlook_inbox is the object poining to my inbox
    print(email_message .datetime_received)
TLanni
  • 330
  • 1
  • 4
  • 15

1 Answers1

1

Do you mean local timezone of where you are located, or local time of where the user is located?

You can get the former via msg.datetime_received.localize(account.default_timezone)

The latter only really makes sense for calendar items where the local timezone has a semantic meaning. It's a bit more complicated (we should make an official method for this):

some_meeting.start.localize(some_meeting._start_timezone)
some_meeting.end.localize(some_meeting._end_timezone)
Erik Cederstrand
  • 9,643
  • 8
  • 39
  • 63