vendredi 29 mai 2015

Python time comparison at midnight

I have to save the time in AM PM format.

But i am having trouble in deciding how to enter midnight time.

Suppose the time is 9PM to 6AM next morning. I have to divide it into day to day basis . Like this

t1 = datetime.datetime.strptime('09:00PM', '%I:%M%p').time()

t2 = datetime.datetime.strptime('12:00AM', '%I:%M%p').time()

t3 = datetime.datetime.strptime('06:00AM', '%I:%M%p').time()

Now i want to know whether the t2 should be

12:00 AM or 11.59PM

If i do 12:00AM then i can't compare if 9pm > 12am but 11.59 looks odd or may be it is right way

Aucun commentaire:

Enregistrer un commentaire