python 时间格式 及 转换 文件时间说明
2017-09-06 20:18
471 查看
#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'
相关文章推荐
- 使用ffmpeg转换文件格式,及ffmpeg参数说明
- python实现txt文件格式转换为arff格式
- 时间转换为字符串格式说明
- python 在linux中把doc转换为docx格式文件(支持word97和word2003)
- python html格式的pdf转换成pdf文件
- 【python3】文件格式转换windows转为unix
- 关于python下各种时间格式的转换
- 一个获取指定目录下一定格式的文件名称和文件修改时间并保存为文件的python脚本
- python sys,os,time模块的使用(包括时间格式的各种转换)
- python将.ppm格式图片转换成.jpg格式文件
- Python3 将configparser从ini文件中读取的内容转换成字典格式
- python时间戳转换时间格式
- 【Python】读取一个目录,将文件名称转换成 json 格式
- python实现将txt文件格式转换为arff格式
- 【Python爬虫实战--2】时间戳转换为指定格式日期
- python转换格式,Matlab读取文件
- java/python中获取当前系统时间,并与字符串相互转换格式,或者转化成秒数,天数等整数
- 测井曲线wis文件格式转换为ASCII文本格式小软件的开发(C与Python结合开发)
- Python:将utf-8格式的文件转换成gbk格式的文件
- python转换时间戳和日期时间格式的转换