python获取当前时间和前一天时间

ime模块:

import time
time.strftime('%Y%m%d')  //time.strftime('%Y-%m-%d-%H:%M:%S')

//获取了当前时间的年月日

datetime:

获取昨天的时间

import datetime
now_time = date time.datetime.now()
yes_time = now_time + date time.timedelta(days=-1)
yes_time_nyr = yes_time.strftime('%Y%m%d')//格式化输出

猜你喜欢

转载自www.cnblogs.com/lili414/p/9048043.html