Reading the local date and time on the email in python using exchangelib

790 Views Asked by At

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)
1

There are 1 best solutions below

0
On BEST ANSWER

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)