0

Using Imaplib in Python , I want to extract the datetime of the email in (GMT-06:00) Central Time (US & Canada) format.

Below are the sample Dates when using msg["date"]

Tue, 14 Jul 2020 08:30:01 +0530
Tue, 14 Jul 2020 02:59:49 +0000
Mon, 13 Jul 2020 21:53:30 -0500 (CDT)
Mon, 13 Jul 2020 18:14:36 -0600
Mon, 13 Jul 2020 16:44:06 -0700
Wed, 8 Jul 2020 20:11:26 +0530 
  • your timestamps mostly seem to contain only a UTC offset - you cannot parse that unambiguously to a specific timezone, only datetime that is aware of the UTC offset. Do you have any other information from which you can infer the timezone? – FObersteiner Jul 15 '20 at 10:30
  • No , I dont have anyother information to infer the timezone. – Nagasri Varma Jul 16 '20 at 09:30
  • if it is ok for you to only work with the UTC offset, I'd suggest to do that. Otherwise, I don't see a way to derive specific timezones without the risk of getting into trouble... see also [this](https://stackoverflow.com/questions/11657273/how-to-pick-a-timezone-based-on-utc-offset) question. `strptime` format for your data should be `'%a, %d %b %Y %H:%M:%S %z'`; but you need to remove suffixes like `(CDT)` before parsing. – FObersteiner Jul 16 '20 at 09:37

0 Answers0