python datetime的加减操作
来源:互联网 发布:淘宝手机下单减价 编辑:程序博客网 时间:2024/05/29 19:24
python时间操作有很多,今天根据业务需求需要做时间的加减操作,找了很久没找到。在此记录,以防忘记
from datetime import timedelta
timedelta可以做时间的加减操作
一下是官方的解释
class datetime.timedelta([days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]]]]]]])All arguments are optional and default to 0. Arguments may be ints, longs, or floats, and may be positive or negative.Only days, seconds and microseconds are stored internally. Arguments are converted to those units:A millisecond is converted to 1000 microseconds.A minute is converted to 60 seconds.An hour is converted to 3600 seconds.A week is converted to 7 days.and days, seconds and microseconds are then normalized so that the representation is unique, with0 <= microseconds < 10000000 <= seconds < 3600*24 (the number of seconds in one day)-999999999 <= days <= 999999999If any argument is a float and there are fractional microseconds, the fractional microseconds left over from all arguments are combined and their sum is rounded to the nearest microsecond. If no argument is a float, the conversion and normalization processes are exact (no information is lost).If the normalized value of days lies outside the indicated range, OverflowError is raised.Note that normalization of negative values may be surprising at first. For example,>>> from datetime import timedelta>>> d = timedelta(microseconds=-1)>>> (d.days, d.seconds, d.microseconds)(-1, 86399, 999999)
具体用法:
time = timedelta(minutes=1)datetime.now + time
minutes处可以填写单位,后边关联的是具体的时间,然后和你需要的时间直接进行加减操作
阅读全文
0 0
- python datetime的加减操作
- python datetime 日期加减
- Python日期的加减等操作
- Python日期的加减等操作
- Python日期的加减等操作
- [Python]datetime常用的几个操作
- python操作Excel的datetime数据
- python time,datetime 操作
- python中datetime操作
- js datetime加减
- python datetime,time转换操作
- python datetime模块基本操作
- Python datetime time 常用操作
- time,datetime------python操作日期和时间的方法
- Python中time和datetime模块对时间的操作
- 关于DateTime的操作
- DateTime 相关的操作
- C# 怎样将DateTime类型进行日期的加减
- studio快捷键(后面会在遇到的时候持续更新)
- Hello CSDN!
- linux shell 管道命令(pipe)使用及与shell重定向区别
- 设计模式
- 关于spring 启动类公共配置
- python datetime的加减操作
- HDU 6119 小小粉丝度度熊【尺取法】
- HTML5-调用-购物车商品(del)-班级添加-也买酒
- 16、图
- java基础学习总结——面向对象1
- 数据库详解
- kendo grid表格加载完成之后触发事件dataBound
- 图的深度优先遍历和广度优先遍历
- LRCN(1)