Compare two datetime objects and print the results in minutes and seconds separately.
My code:
def onJoin(self, room, user): #called when user joins the room
user.entryTime = datetime.datetime.now()
print("[i] %s joined the room!" % user.name)
def onLeave(self, room, user): #called when the user leaves the room
try:
user.exitTime = datetime.datetime.now()
user.spentTime = user.exitTime - user.entryTime
time = divmod(user.spentTime.days * 86400 + user.spentTime.seconds, 60)
print('[i] %s spent %s in total.' % (user.name, time))
except:
print('[i] Where the fuck did %s come from? O.o' % user.name) #if the user leaves without joining first.
And this is the result:
[i] tryhardhusky joined the room! [i] tryhardhusky spent (0, 3) in total.
The first number is minutes, and the second is seconds.
This works fine, But would like the minutes and seconds to print separate.
Like this:
[i] tryhardhusky joined the room! [i] tryhardhusky spent 0 minutes and 3 seconds in total.
I'm rather new to the datetime module, and really dont know how I would get this result
If anyone could help, It would be much appreciated
Thanks in advance
This post has been edited by Inuinu172: 03 December 2013 - 01:13 AM

New Topic/Question
Reply


MultiQuote




|