0

I need to parse the following time:

 mytime = "11:32  PM LT"
 datetime.strptime(mytime,  '%H:%M %p LT')

But sometimes "11:32 PM LT" is a GMT time like for example "18:32 PM GMT". How do I parse that correctly so both time types are taken into consideration?

David
  • 2,926
  • 1
  • 27
  • 61
  • Please check https://stackoverflow.com/questions/7065164/how-to-make-an-unaware-datetime-timezone-aware-in-python – Rockybilly Jun 26 '19 at 17:31
  • if you can put timezone as an offset then you use %z as datetime.strptime(mytime, '%H:%M %p %z') – vk-code Jun 26 '19 at 18:49

1 Answers1

1

Please try the dateutil package.

parse('11:32  PM GMT')
datetime.datetime(2019, 6, 26, 23, 32, tzinfo=tzutc())
Stanton
  • 497
  • 3
  • 14