- 判断时间是否达到提交日志的时间
- 生成0点01分的时间戳
- 生成当前日期精确到秒的时间
- 生成当前日期的字符串用于文件保存
"""
@filename:timeHandle.py
@author:LinXingNan
@time:2023-11-27
"""
import datetime
from datetime import datetime
from datetime import timedelta
def is_time_reached(hour, minute):
current_time = datetime.now().time()
specified_time = (
datetime.now().replace(hour=hour, minute=minute, second=0, microsecond=0).time()
)
return current_time >= specified_time
def get_midnight_timestamp():
midnight = datetime.now().replace(hour=0, minute=1, second=0, microsecond=0)
return int(midnight.timestamp())
def get_tomorrow_timestamp(base_timestamp):
if base_timestamp is None:
tomorrow = datetime.now() + timedelta(days=1)
else:
tomorrow = datetime.fromtimestamp(base_timestamp) + timedelta(days=1)
tomorrow_midnight = tomorrow.replace(hour=0, minute=1, second=0, microsecond=0)
return int(tomorrow_midnight.timestamp())
def get_current_date_string():
current_datetime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
return current_datetime
def get_current_date_to_file():
current_datetime = datetime.now().strftime("%Y-%m-%d")
return current_datetime