python3 获取n年前日期
code
import time import datetime import random #13位时间戳 temp=time.time() timestamp=int(round(temp*1000)) str_timestamp=str(timestamp) t=datetime.datetime.now() #15年前 d2=(t+datetime.timedelta(days=-365*15)).strftime("%Y%m%d") #23年前 d3=(t+datetime.timedelta(days=-365*23)).strftime("%Y%m%d") print(str_timestamp) print(d2) print(d3)
输出
macname@MacdeMacBook-Pro Desktop % python3 test.py 1610095883568 20060112 19980114 macname@MacdeMacBook-Pro Desktop %