PDA

View Full Version : [Python] Seconds past midnight



ki4jgt
May 23rd, 2011, 04:00 PM
In an old language which I programmed in before Python I was able to calculate seconds past midnight by using: time(seconds) Is there a feature in Python for this?

simeon87
May 23rd, 2011, 04:08 PM
Have a look at the datetime (http://docs.python.org/library/datetime.html) module.


import datetime
a = datetime.datetime(2011,5,23)
b = a + datetime.timedelta(seconds=10)

LeDroid
June 1st, 2012, 04:34 PM
a = datetime.datetime(2011,5,23,15,30,45)
# print seconds past midnight
print (a - datetime.datetime.min).seconds

# Should display 55845