码迷,mamicode.com
首页 > 其他好文 > 详细

日期时间的运算

时间:2018-04-24 13:58:04      阅读:155      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!