View Full Version : [Python] Seconds past midnight
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?
May 23rd, 2011, 04:08 PM
Have a look at the datetime (http://docs.python.org/library/datetime.html) module.
a = datetime.datetime(2011,5,23)
b = a + datetime.timedelta(seconds=10)
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
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.