I have the following string:
08 Jan 2018 08:45:30 +0100
which I would like to conert to a unix timestamp. I know how to convert a time from this answer Convert string date to timestamp in Python , however this only describes how to do it if the name is given as a number like 01/12/1991
. Furthermore, I do not know how to include the timezoen (+0100) into the conversion.
For the month I would have come up with a look up table which is a workaround, and I thought there may be a better way to do this
Here is the code I came up with for that:
lookup = {}
lookup['Jan'] = '01'
lookup['Feb'] = '02'
lookup['Mar'] = '03'
lookup['Apr'] = '04'
lookup['Mai'] = '05'
lookup['Jun'] = '06'
lookup['Jul'] = '07'
lookup['Aug'] = '08'
lookup['Sep'] = '09'
lookup['Okt'] = '10'
lookup['Nov'] = '11'
lookup['Dec'] = '12'
dates_to_convert = '08 Jan 2018 08:45:30 +0100'
dates_to_convert.replace(dates_to_convert.split()[1],lookup[dates_to_convert.split()[1]])
## Now continue with solution from linked answer...