I have a string that says "Oct. 2, 2017, midnight" and want to convert it to a UTC timestamp.
Is there any good way to do this?
I have a string that says "Oct. 2, 2017, midnight" and want to convert it to a UTC timestamp.
Is there any good way to do this?
Considering all your data is at midnight, the easiest way is to remove the , midnight
string and convert it.
import datetime
import pytz
s = "Oct. 2, 2017, midnight"
dt = datetime.datetime.strptime(s.split(', midnight')[0], '%b. %d, %Y')
dt_utc = dt.astimezone(pytz.utc)
If there are other time indicated, you'll want to interpret the literals of the time and pass it onto strptime()
accordingly.