How to print month, day, year and hour, minute, second separately in Python

2 Answers

0 votes
import datetime

now = datetime.datetime.now()

print("day -  %s" % now.day)

print("month - %s" % now.month)

print("year - %s" % now.year)

print("hour - %s" % now.hour)

print("minute - %s" % now.minute)

print("second -  %s" % now.second)

'''
run:

day -  23
month - 6
year - 2015
hour - 19
minute - 25
second -  36

'''

 



answered Jun 23, 2015 by avibootz
0 votes
import datetime

now = datetime.datetime.now()

print("dd/mm/yyyy -  %s/%s/%s" % (now.day, now.month, now.year))

print("hh:mm:ss - %s:%s:%s" % (now.hour, now.minute, now.second))

'''
run:

dd/mm/yyyy -  23/6/2015
hh:mm:ss - 19:30:14

'''

 



answered Jun 23, 2015 by avibootz
...