python时间戳于时间格式字符串相互转换的方法
1.当前时间:
import time
timestamp = int(time.time()) #获取当前时间戳
timestruct = time.localtime(timestamp) #获取当前时间的时间数组,tm_year,tm_mon,tm_wday.....
str_time = time.strftime("%Y%m%d %H:%M:%S",timestruct) #时间戳转成字符串
2.特定时间的字符串:
import time
date ='20150610'
timestruct = time.strptime(date,"%Y%m%d") #时间字符串转成时间
timestamp = int(time.mktime(time.struct)) #转成时间戳