python - 如何创建一个等于 15 分钟前的 DateTime?

标签 python datetime

我需要创建一个表示当前时间减去 15 分钟的 DateTime 对象。

最佳答案

导入日期时间,然后导入神奇的 timedelta 内容:

In [63]: datetime.datetime.now()
Out[63]: datetime.datetime(2010, 12, 27, 14, 39, 19, 700401)

In [64]: datetime.datetime.now() - datetime.timedelta(minutes=15)
Out[64]: datetime.datetime(2010, 12, 27, 14, 24, 21, 684435)

关于python - 如何创建一个等于 15 分钟前的 DateTime?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4541629/

相关文章:

python - 相机校准代码-OpenCV错误:断言失败

python - 将随机 True 或 False 附加到 Python 中每行的末尾

python - 如何动态代理类的方法?

python - 在 Windows 上安装 rasa

python - gsteramer appsink 内存泄漏(python 绑定(bind))

python - 如何用冒号解析时区

R 错误 : unknown timezone with as. POSIXct()

python - 如何更改 pandas 中的时间格式?

datetime - 您如何将秒数转换为 HH :MM:SS format in SQLite?

php - 如何使用 MySQL 存储 UNIX 时间戳