效果如图:

python获取当前日期0点0分的日期格式

 

 代码如下:

# 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

相关文章:

  • 2022-12-23
  • 2021-12-05
  • 2021-11-18
  • 2022-12-23
  • 2022-02-06
  • 2022-01-09
  • 2022-12-23
  • 2021-11-28
猜你喜欢
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
  • 2021-11-28
相关资源
相似解决方案