mardi 28 avril 2015

Conversion of datetime in python

Trying to use datetime to get an age of ec2 instance by comparing launch_time to current time. All working fine by using format below: datetime.datetime.strptime(instance.launch_time, "%Y-%m-%dT%H:%M:%S.%fZ")

Unfortunately I've got an one with 0 microseconds, so getting an error about not matching format (time data '2015-03-16T03:21:05Z' does not match format '%Y-%m-%dT%H:%M:%S.%fZ') 2015-03-16T03:02:12.910Z 2015-03-16T03:21:05Z - this one is problematic 2015-03-25T09:19:34.018Z

Any idea how to get around this? It looks like datetime is the easiest way to get this sorted but if there are quicker way of doing that, happy to see other options. FYI, comparision has to be done up to hour, so don't care about seconds ;)

Thanks, Andre




Aucun commentaire:

Enregistrer un commentaire