Datetime.now() hours mins secs


#1

from datetime import datetime
now = datetime.now()
print now.hour
print now.minute
print now.second
print '%:%:%' % (now.hour, now.minute, now.second)

this is my code that i have and its telling me that the collen is the problem? idk what to do

ValueError: unsupported format character ':' (0x3a) at index 1


#2

jk i looked it up on stockoverflow and figured it out


#3

if anyone else gets stuck here just make sure you have s's behind all the placeholders(%)
print '%s:%s:%' % (now.hour, now.minute, now.second)
if the rest of you code is fine this should work it worked for me


#4

@bodangles21,

from datetime import datetime
now = datetime.now()
print now.hour
print now.minute
print now.second
print '%s:%s:%s' % (now.hour, now.minute, now.second)
print '%02d:%02d:%02d' % (now.hour, now.minute, now.second)
now = datetime.now()
now_tuple = (now.month,now.day,now.year,now.hour,now.minute,now.second)
now_format = "%02d/%02s/%s %02d:%02d:%02d"
print now_format % now_tuple