python 与时间有关的操作

python保存时间戳文件

import time
# ISOTIMEFORMAT='%Y-%m-%d %X'
ISOTIMEFORMAT='%Y-%m-%d'
t= time.strftime( ISOTIMEFORMAT, time.gmtime( time.time() ) )
f = open( t + "test.txt",'wb')
f.write("hello,
 This is a test file")
f.close()

计算程序运行时间

import time
# ISOTIMEFORMAT='%Y-%m-%d %X'
start = time.time()
ISOTIMEFORMAT='%Y-%m-%d'
t= time.strftime( ISOTIMEFORMAT, time.gmtime( time.time() ) )
f = open( t + "test.txt",'wb')
f.write("hello,
 This is a test file")
f.close()
print t
elapsed = time.time() - start
print elapsed

out:

2016-05-31
0.00300002098083
原文地址:https://www.cnblogs.com/Qwells/p/5547010.html