时间戳to时间to字符串 python

来源:互联网 发布:软件界面上面不见了 编辑:程序博客网 时间:2024/04/30 13:39
import time# 时间转 strdef date2str(d):    s = time.strftime("%Y-%m-%d", d)    return s    # 时间戳转换为时间def tamp2date(timestamp):    d = time.localtime(timestamp)    return d# str 转换时间戳def str2date(t):    d = time.mktime(time.strptime(t, "%Y-%m-%d"))    return ddate = '2017-03-12'if str2date(date) > time.time():    time_struct = tamp2date(str2date(date)- 60*60*24*365)    print time_struct

0 0