1

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.

David Buck
  • 3,752
  • 35
  • 31
  • 35
Tamara2607
  • 13
  • 2
  • Does this answer your question? [How do I parse an ISO 8601-formatted date?](https://stackoverflow.com/questions/127803/how-do-i-parse-an-iso-8601-formatted-date) – FObersteiner Nov 08 '21 at 13:27

1 Answers1

1

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