I am parsing some data that has the leapsecond timestampe datetime 2012-06-30T23:59:60.209215
. I used following code to parse that string and convert to a datetime object:
nofrag, frag = t.split('.')
nofrag_dt = datetime.datetime.strptime(nofrag, "%Y-%m-%dT%H:%M:%S")
dt = nofrag_dt.replace(microsecond=int(frag))
Python documentation claims that this shouldn't be an issue as %S
accepts [0, 61]
. But, I get this error with the above timestamp
nofrag_dt = datetime.datetime.strptime(nofrag, "%Y-%m-%dT%H:%M:%S")
ValueError: second must be in 0..59
Thanks
time.strptime
and works fine; the problem is that if the seconds are > 59, it can't be converted back to adatetime.datetime
.int(frag)
may return a wrong number of microseconds e.g.,.123
should correspond to123000
microseconds, not123
.