使用 datetime 模块来获取当前详细时间,并将当前时间减去或增加多少
import datetime # 当前时间减去两分钟 ctime = datetime.datetime.now() + datetime.timedelta(minutes=-2) # 当前时间减去两小时 ctime = datetime.datetime.now() + datetime.timedelta(hours=-2) ... # 点进 timedelta 查看源码可以看到以下参数都可以自己设置 class timedelta(SupportsAbs[timedelta]): min: ClassVar[timedelta] max: ClassVar[timedelta] resolution: ClassVar[timedelta] if sys.version_info >= (3, 6): def __init__(self, days: float = ..., seconds: float = ..., microseconds: float = ..., milliseconds: float = ..., minutes: float = ..., hours: float = ..., weeks: float = ..., *, fold: int = ...) -> None: ... else: def __init__(self, days: float = ..., seconds: float = ..., microseconds: float = ..., milliseconds: float = ..., minutes: float = ..., hours: float = ..., weeks: float = ...) -> None: ...
...