python获取前一天凌晨零点到23:59的时间

now = time.time()
midnight = now - (now % 86400) + time.timezone
pre_midnight = midnight - 86400
now_midnight = midnight - 1
start_time = datetime.datetime.strptime(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(pre_midnight)), "%Y-%m-%d %H:%M:%S")
end_time = datetime.datetime.strptime(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(now_midnight)), "%Y-%m-%d %H:%M:%S")

转载于:https://my.oschina.net/u/2440810/blog/1791289

你可能感兴趣的:(python获取前一天凌晨零点到23:59的时间)