乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Python計算文件創(chuàng)建的天數(shù)之os、time、datetime

       禁忌石 2022-12-11 發(fā)布于浙江

      20221203記錄


      import os,time,datetimefilepath = r'E:\chromedriver.exe'# 1,文件的創(chuàng)建時間(時間戳):# <class 'float'> 1664002851.0419765ctime = os.path.getctime(filepath)print(type(ctime),ctime)# 2,時間戳轉(zhuǎn)換成本地時間:# <class 'time.struct_time'> time.struct_time(tm_year=2022, tm_mon=9, tm_mday=24, tm_hour=15, tm_min=0, tm_sec=51, tm_wday=5, tm_yday=267, tm_isdst=0)locatime = time.localtime(ctime)print(type(locatime),locatime)# 3,本地時間轉(zhuǎn)換成字符串:# <class 'str'> 2022-09-24 15:00:51strtime = time.strftime('%Y-%m-%d %H:%M:%S',locatime)print(type(strtime),strtime)'''注意:datetime.datetime.strftime(),也可以進行時間轉(zhuǎn)字符串,但是這里 locatime 不符合datetime的轉(zhuǎn)換類型條件,會報錯如下:TypeError: descriptor 'strftime' for 'datetime.date' objects doesn't apply to a 'time.struct_time' object所以如下的 strtime02 不可以,strtime03可以;strtime02 = datetime.datetime.strftime(locatime,'%Y-%m-%d %H:%M:%S')strtime03 = datetime.datetime.strftime(datetime.datetime.today(),'%Y-%m-%d %H:%M:%S')'''# 4,字符串轉(zhuǎn)換成日期:# <class 'datetime.datetime'> 2022-09-24 15:00:51datime = datetime.datetime.strptime(strtime,'%Y-%m-%d %H:%M:%S')print(type(datime),datime)'''注意:time.strptime(strtime,'%Y-%m-%d %H:%M:%S') 也可以進行字符串轉(zhuǎn)換成日期,但是得到的數(shù)據(jù)如下,這種日期數(shù)據(jù)不直觀:<class 'time.struct_time'> time.struct_time(tm_year=2022, tm_mon=9, tm_mday=24, tm_hour=15, tm_min=0, tm_sec=51, tm_wday=5, tm_yday=267, tm_isdst=-1)所以這里使用 datetime.datetime.strptime(strtime,'%Y-%m-%d %H:%M:%S') 進行轉(zhuǎn)換'''# 5,計算文件創(chuàng)建的天數(shù):nowday = datetime.datetime.today()print(type(nowday),nowday) # <class 'datetime.datetime'> 2022-12-03 15:04:39.670033ndays = (nowday-datime).daysprint(ndays) # 70
      文章圖片1
      文章圖片2

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多