• 每天进步一点点!

文章分类

推荐网站

常用手册

python时间格式化【原创】

#!/usr/bin/env python

import time

#strtime to timestamp
strTime = "2013-11-05 14:51:43"
timestamp = time.mktime(time.strptime(strTime,'%Y-%m-%d %H:%M:%S'))

print timestamp

#timestamp to string time
print time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(timestamp))

#get now timestamp
print time.time()

#fomate right now timestamp to string time
print time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))

#output
#1383634303.0
#2013-11-05 14:51:43
#1383634321.24
#2013-11-05 14:52:01
类别:Python | 浏览(82) | 评论(0) | 阅读全文>>