python中 timedelta对象学习记录
上一篇 /
下一篇 2017-04-23 10:30:12
/ 个人分类:python
timedelta介绍:
具体各个参数介绍及使用方法见下面代码,标红部分为注释及输出
对象初始化输入数据如下:
datetime.
timedelta
([days[,seconds[,microseconds[,milliseconds[,minutes[,hours[,weeks]]]]]]])
#coding:utf-8
import os
import datetime
from os import path
if __name__ == '__main__':
date = datetime.timedelta.max#最大值为999999999 days, 23:59:59.999999
print date
print date.days,date.seconds,date.microseconds#999999999 86399 999999
print datetime.timedelta.min#最小值为-999999999 days, 0:00:00
print datetime.timedelta()#默认值为全0 0:00:00
#days的取值范围为-999999999 <= days <= 999999999
print datetime.timedelta(days=-999999999)#
print datetime.timedelta(days=-999999999)#
#days的值超出范围后就会提示OverflowError: days=-1000000000; must have magnitude <= 999999999
#print datetime.timedelta(days=-1000000000)
#OverflowError: days=1000000000; must have magnitude <= 999999999
# print datetime.timedelta(days=1000000000)
#seconds 的取值范围为0 <= seconds < 3600*24超出后会进行跳变
print datetime.timedelta(seconds=-1)#值跳转为最大-1 day, 23:59:59
print datetime.timedelta(seconds=3600*24)#1 day, 0:00:00
#microseconds 毫秒取值范围0 <= microseconds < 1000000 超出后会进行跳变
print datetime.timedelta(microseconds=-1)#-1 day, 23:59:59.999999
print datetime.timedelta(microseconds=1000000)#0:00:01,超过999999后进1
print datetime.timedelta(microseconds=1000001)#0:00:01.000001
print datetime.timedelta(microseconds=0)#0:00:00
#minutes 的取值范围为0 <= minutes <60,超出范围后进行跳变
print datetime.timedelta(minutes=60)#1:00:00,超59进1
print datetime.timedelta(minutes=-1)#-1 day, 23:59:00,小于0后减1
#hours 的取值范围为0 <= hours <23,超出范围后进行跳变
print datetime.timedelta(hours=24)#1 day, 0:00:00,超23后进1
print datetime.timedelta(hours=-1)#-1 day, 23:00:00,小于0后减1
#weeks 乘7后转换成day的值,使用day的取值范围进行计算
# print datetime.timedelta(weeks=999999999/7+1)#OverflowError: days=1000000001; must have magnitude <= 999999999
相关阅读:
- python中os模块renames学习记录 (zwtravel, 2017-4-16)
- 根据进程名获取进程PID的python实现 (jiaxunfeihong, 2017-4-17)
- python datetime模块 (wangxiangjian, 2017-4-17)
- Python自动化测试番外篇—接口测试 (zaza9084, 2017-4-25)
- 干货 | Python 2 常用的爬虫技巧总结(转) (博为峰网校, 2017-4-19)
- 基于python+selenium的测试框架 (lamecho, 2017-4-19)
- Python学习之路—Python切片模拟LRU算法 (zaza9084, 2017-4-20)
- Appium+Python做移动端自动化测试 (zaza9084, 2017-4-20)
- 用Python Requests类来实现接口测试 (zaza9084, 2017-4-21)
- 测试女巫之接口测试篇 (zaza9084, 2017-5-19)
收藏
举报
TAG:
Python
python