Ank*_*Ank 21 python date unix-timestamp
我正在尝试以mm/dd/yyyy格式获取文件上的日期戳
time.ctime(os.path.getmtime(file))
Run Code Online (Sandbox Code Playgroud)
给我详细的时间戳 Fri Jun 07 16:54:31 2013
如何将输出显示为 06/07/2013
Mar*_*ers 41
您想用来time.strftime()
格式化时间戳; 首先使用time.gmtime()
或将其转换为时间元组time.localtime()
:
time.strftime('%m/%d/%Y', time.gmtime(os.path.getmtime(file)))
Run Code Online (Sandbox Code Playgroud)
小智 6
from datetime import datetime
from os.path import getmtime
datetime.fromtimestamp(getmtime(file)).strftime('%m/%d/%Y')
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
35251 次 |
最近记录: |