python time模块 时间处理

import time
import re

print time.time()
print time.localtime()
a = 'tm_year=2016, tm_mon=5, tm_mday=28, tm_hour=6, tm_min=51, tm_sec=14, tm_wday=5, tm_yday=149, tm_isdst=0'
b = re.findall('\d+', a)
print b
c = []
for tup in b:
t = int(tup)
c.append(t)
c = tuple(c)
print type(c)
print c
# c = (2016, 5, 28, 6, 51, 14, 5, 149, 0)
print time.mktime(c)
print time.mktime(time.localtime(1464389474.0)) # 元组转化为时间戳,struct_time --->时间戳
print time.localtime(1464389474.0)
print time.gmtime(1464389474.0) # 时间戳转化为元组, 时间戳--->struct_time
print time.strftime('%Y-%m-%d %H:%M:%S:%a:%b:%c:%j %p %U %w %W %x', time.localtime(1464389474.0))
print time.strftime('%Y-%m-%d %H:%M:%S') # struct_time --->格式化字符串
print time.strptime('2016-05-28 06:51:14', '%Y-%m-%d %H:%M:%S') #格式化字符串 --->struct time

#元组和字符串无法直接相互转化

#datetime

posted @ 2016-05-28 17:35  3one  阅读(146)  评论(0编辑  收藏  举报