I just want to add an hour to the Twitter time format. The one I got is:
start_time = '2021-03-11T00:00:00.000Z'
I googled for several hours now, but nothing works. I always get errors such as the time date does not match the format.
I just want to add an hour to the Twitter time format. The one I got is:
start_time = '2021-03-11T00:00:00.000Z'
I googled for several hours now, but nothing works. I always get errors such as the time date does not match the format.
There are many ways to do this. Here's one...
Install python-dateutil then:
from dateutil import parser
from datetime import timedelta
start_time = '2021-03-11T00:00:00.000Z'
d = parser.isoparse(start_time)
d += timedelta(hours=1)
print(f"{d.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3]}Z")
The strftime function produces 6 decimal places. So, to keep your original format you'll need to strip off the last 3 digits then add the Z