import locale
from datetime import datetime,date,time
locale.setlocale(locale.LC_CTYPE, 'chinese')
print(datetime.now()) #返回當天的日期和時間,datetime類型
today=datetime.now() #定義today為當前日期時間對象
print(datetime.date(today)) #返回當天的日期對象,date類型
print(datetime.time(today)) #返回當天的時間對象,time類型
print(datetime.ctime(today)) #獲取“星期,月,日,時,分,秒,年”格式的字符串
print(datetime.utcnow()) #返回當前的UTC日期和時間,datetime類型
print(datetime.timestamp(today)) #返回當天的時間戳(UNIX時間戳),浮點數類型
print(datetime.fromtimestamp(datetime.timestamp(today))) #根據時間戳返回UTC日期時間,datetime類型
date1=date(2018,2,12)
time1=time(20,53,48)
print(datetime.combine(date1,time1)) #綁定日期、時間,生成新的datetime對象
newDatetime=datetime.strptime('2021-08-03 22:53:0', '%Y-%m-%d %H:%M:%S') #使用字符串和指定格式生成新的datetime對象
print(newDatetime)
for tv in datetime.timetuple(today):
print(tv)
print(today.isocalendar()) #ISO格式的日期
print(today.strftime("%Y年%m月%d日 %H:%M:%S %p"))