题目:
获取当前的日期和时间
思路:
1、调用 datetime模块
2、输出即可
结果:
import datetime
# 获取当前的时间
now_time = datetime.datetime.now()
print(now_time,type(now_time))
# 格式化输出当前时间
str_now_time = now_time.strftime("%Y-%m-%d %H:%M:%S")
print(str_now_time)
print("year",now_time.year)
print("month",now_time.month)
print("day",now_time.day)
print("hour",now_time.hour)
print("minute",now_time.minute)
print("second",now_time.second)
-------------------------------------
2022-11-15 13:07:03.606942 <class 'datetime.datetime'>
2022-11-15 13:07:03
year 2022
month 11
day 15
hour 13
minute 7
second 3
标签:30,year,second,datetime,获取,日期,time,print,now From: https://www.cnblogs.com/LoLong/p/16892096.html