<pre name="code" class="plain">
首先导入time,和datetime包
import datetime import time
实现代码如下:
if __name__ == '__main__': dt=sys.argv[1] myday = datetime.datetime( int(dt[0:4]),int(dt[5:7]),int(dt[8:10]) ) + datetime.timedelta(days=-1) dt = myday.strftime('%Y-%m-%d') timestamp = int(time.mktime(time.strptime(dt, "%Y-%m-%d"))) print dt datetime.timedelta() now_time = datetime.datetime.now() yes_time = now_time + datetime.timedelta(days=-2) # yes_time_nyr = last_time.strftime('%Y%m%d') print now_time print yes_time print yes_time.strftime('%Y-%m-%d')
运行命令: python test.py 2015-04-01
输出结果:
2015-03-31
2015-04-01 10:46:28.099195
2015-03-30 10:46:28.099195
2015-03-30
时间: 2024-10-15 21:55:35