How to get current time and break it into year, month, day, hour, minute and second in Python

2 Answers

0 votes
import datetime

now = datetime.datetime.now()

print(now.year, "-", now.month, "-", now.day, sep='')
print(now.hour, ":", now.minute, ":", now.second, sep='')


'''
run:

2017-11-6
21:32:28

'''

 



answered Nov 6, 2017 by avibootz
edited Nov 6, 2017 by avibootz
0 votes
import time

year, month, day, hour, minute, second = time.strftime("%Y,%m,%d,%H,%M,%S").split(',')

print(year, "-", month, "-", day, sep='')
print(hour, ":", minute, ":", second, sep='')


'''
run:

2017-11-06
21:46:18

'''

 



answered Nov 6, 2017 by avibootz
...