首页 > 其他 > 详细

日期时间的运算

时间:2018-04-24 13:50:39      阅读:204      评论:0      收藏:0      [点我收藏+]
一、日期时间计算

1)timedelta 两个datetime之差

次类中包含如下属性:

1 、days 天数

2、 microseconds 微秒 (>=0并且<1秒)

3 、seconds: 秒数(>=0并且<1天)

 

演示:

from datetime import datetime

 

dt01 = datetime(2012, 12, 12, 12, 12, 12, 121212)

dt02 = datetime(2013, 11, 13, 13, 13, 11, 131313)

print(dt01 - dt02)

print(abs((dt01 - dt02).days)) # 相差多少天

print(abs((dt01 - dt02).seconds)) # 相差多少秒

print(abs((dt01 - dt02).microseconds)) # 相差多少微秒

 

print(dt01.strftime("%Y-%m-%d %H:%M:%S."), dt01.microsecond,end="")

print(dt02.strftime("%Y-%m-%d %H:%M:%S."), dt02.microsecond,end="相差")

print(abs((dt01-dt02).days),"",abs((dt01-dt02).seconds),"",abs((dt01-dt02).microseconds),"微秒")


日期时间的运算

原文:http://blog.51cto.com/13043937/2107179

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!