本文介绍了在Python中查找两个日期之间的中点日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出日期:
my_guess = '2014-11-30'
their_guess = '2017-08-30'
如何在日期之间分割差额,返回正确的日历日期?
How do I split the delta between the dates, returning the correct calendar date?
推荐答案
一种方法是使用 datetime
。找到两个日期之间的差,将其减半,然后将其添加到较早的日期:
One way would be to use datetime
. Find the difference between two dates, halve it, and add it on the earlier date:
>>> from datetime import datetime
>>> a = datetime(2014, 11, 30)
>>> b = datetime(2017, 8 ,30)
>>> a + (b - a)/2
2016-04-15 00:00:00
这篇关于在Python中查找两个日期之间的中点日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!