python時間フォーマットおよび変換ファイル時間説明
3550 ワード
#coding: utf-8
__author__ = 'KK'
import time
# Wed Sep 06 20:14:46 2017
print time.ctime()
# 1504700086.44
print time.time()
# struct_time time.struct_time(tm_year=2017, tm_mon=9, tm_mday=6, tm_hour=20, tm_min=14, tm_sec=46, tm_wday=2, tm_yday=249, tm_isdst=0)
print time.localtime()
# 2017_09_06 20:14:46
print time.strftime("%Y_%m_%d %H:%M:%S")
:
import os import time import datetime # file ="D:\\log.txt" timestamp = os.path.getmtime(file) #1504700941.93 print timestamp #time.struct_time(tm_year=2017, tm_mon=9, tm_mday=6, tm_hour=20, tm_min=29, tm_sec=1, tm_wday=2, tm_yday=249, tm_isdst=0) print time.localtime(timestamp) #2017-09-06 20:29:01.934336 print datetime.datetime.fromtimestamp(timestamp) #2017-09-06 print datetime.date.fromtimestamp(timestamp) #time.struct_time(tm_year=2017, tm_mon=9, tm_mday=6, tm_hour=12, tm_min=29, tm_sec=1, tm_wday=2, tm_yday=249, tm_isdst=0) print time.gmtime(os.path.getmtime(file))
# :
print os.path.getatime(file) # 1504700920.69 win2003 SP1 ,= print os.path.getctime(file) # 1504700920.69 print os.path.getmtime(file) # 1504705313.16 print time.gmtime(os.path.getmtime(file)) # struct_time print os.path.getsize(file) # ( ) print os.path.abspath(file) # '/Volumes/Leopard/Users/Caroline/Desktop/1.mp4' print os.path.normpath(file) # '/Volumes/Leopard/Users/Caroline/Desktop/1.mp4'