You are missing .%fZ from your format string.
p = '%Y-%m-%dT%H:%M:%S.%fZ'
The correct way to convert to an era is to use datetime :
from datetime import datetime p = '%Y-%m-%dT%H:%M:%S.%fZ' mytime = "2009-03-08T00:27:31.807Z" epoch = datetime(1970, 1, 1) print((datetime.strptime(mytime, p) - epoch).total_seconds())
Or call int if you want to ignore fractions.
source share