效果如圖:
代碼如下:
# TODO 獲取當前日期0點0分 import time import datetime def current_time(time_options, interval_day): """ :param time_options: time_options == "add_time":增加時間,time_options == "sub_time":減去時間 :param interval_day: 間隔天數 :return: 當前日期0點0分 """ day_time = int(time.mktime(datetime.date.today().timetuple())) if time_options == "add_time": interval_seconds = interval_day * 86400 date = datetime.datetime.fromtimestamp(day_time + interval_seconds) return date elif time_options == "sub_time": interval_seconds = interval_day * 86400 date = datetime.datetime.fromtimestamp(day_time - interval_seconds) return date else: print(f"參數錯誤:{time_options},請檢查") if __name__ == '__main__': a = current_time("sub_time", 14) print(a)
參考:https://blog.csdn.net/pineapple_C/article/details/112347597