欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

一篇文章帶你了解python標(biāo)準(zhǔn)庫--datetime模塊

 更新時間:2021年08月17日 16:05:06   作者:wakeyo_J  
這篇文章主要為大家介紹了python中的datetime模塊,datetime模塊的接口則更直觀、更容易調(diào)用,想要了解datetime模塊的朋友可以參考一下

1. datetime模塊介紹

1.1 datetime模塊包含的類

在這里插入圖片描述

1.2 datetime模塊中包含的常量

在這里插入圖片描述

2. datetime實(shí)例的方法

在這里插入圖片描述

案例代碼

import locale
from datetime import datetime,date,time
locale.setlocale(locale.LC_CTYPE, 'chinese')
print(datetime.now())      #返回當(dāng)天的日期和時間,datetime類型
today=datetime.now()        #定義today為當(dāng)前日期時間對象
print(datetime.date(today)) #返回當(dāng)天的日期對象,date類型
print(datetime.time(today)) #返回當(dāng)天的時間對象,time類型
print(datetime.ctime(today)) #獲取“星期,月,日,時,分,秒,年”格式的字符串
print(datetime.utcnow())    #返回當(dāng)前的UTC日期和時間,datetime類型
print(datetime.timestamp(today))   #返回當(dāng)天的時間戳(UNIX時間戳),浮點(diǎn)數(shù)類型
print(datetime.fromtimestamp(datetime.timestamp(today)))   #根據(jù)時間戳返回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"))

結(jié)果

在這里插入圖片描述

3. 日期格式化符號

strftime()方法和strptime()方法的時間日期格式化符號及所代表意思

在這里插入圖片描述

總結(jié)

本篇文章就到這里了,希望能給你帶來幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!

相關(guān)文章

最新評論