Reputation: 27
I have a problem with converting isoformat to datetime. I have this:
[{'timex-value': '2019-W32T15:00', 'start': 18, 'end': 31, 'text': '3pm next week', 'type': 'TIME', 'value': '2019-W32T15:00'}]
How can I convert '2019-W32T15:00' to datetime format in python?
Upvotes: 2
Views: 139
Reputation: 3200
To get a date time object you would want something like this. However you you will not get a the correct answer because you do not have a day of the week.
import date time as dt
dt.datetime.strptime('2019-W32T15:00','%Y-W%WT%H:%M')
If you want a successful conversion to a date time then specify the first day of that week by adding a 1 to the timex-value
string.
import date time as dt
dt.datetime.strptime('2019-W32T15:00'+'-1','%Y-W%WT%H:%M-%w')
Result: datetime.datetime(2019, 8, 12, 15, 0)
Upvotes: 2