Python 箭头添加小时/分钟/等 vs 替换

标签 python arrow-python

<分区>

我想在 Python 中使用 arrowdatetime,我想将以下示例转换为 arrow:

end_date = start_date + timedelta(days=5)

我在 arrow 文档中看到的唯一内容是:

start_date.replace(weeks=+3)

但我想分配 end_datestart_date 多 5 天 - 不更改现有的 start_date

我不想写,即:

end_date = start_date
end_date.replace(days=+5)

我想在单行中完成...有什么想法吗?

最佳答案

start_date.replace 不会改变 start_date,它会返回一个新对象。所以你可以将它分配给一个新名称:

end_date = start_date.replace(days=+5)

阅读docs很有用。

关于Python 箭头添加小时/分钟/等 vs 替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40590619/

相关文章:

python - Arrow 中的时间戳之间的差异

python - python中用箭头增加日期不改变属性

Python,连接垂直列表

python - 我如何使用 CD 和 LS 等 Linux 终端命令?

python - 将时间作为 HHMM 格式的用户输入

Python 如何从字典中获取所有值同名键

python - 在 Python 中重构循环的方法?

Python 3如何格式化为yyyy-mm-ddThh :mm:ssZ

python - 使用 `arrow` 或 `dateutil` 时如何查找时区数据库版本?