使用python中的datetime获取当前的年份、月份、天数、小时数、分钟数、秒数
import datetime
now = datetime.datetime.now()
print('now is ', now)
print('the year of now is', now.year)
print('the month of now is ', now.month)
print('the day of now is ', now.day)
print('the hour of now is ', now.hour)
print('the minute of now is ', now.minute)
print('the second of now is ', now.second)
结果如下:
('now is ', datetime.datetime(2019, 6, 14, 15, 42, 27, 601210))
('the year of now is', 2019)
('the month of now is ', 6)
('the day of now is ', 14)
('the hour of now is ', 15)
('the minute of now is ', 42)