1.计算日期间隔对应的天数
#计算日期间隔对应的天数
#参考:https://www.cnblogs.com/hellojesson/p/8431457.html def _get_number_of_days(self, date_from, date_to): """Returns a float equals to the timedelta between two dates given as string.""" DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S" from_dt = datetime.datetime.strptime(date_from, DATETIME_FORMAT) to_dt = datetime.datetime.strptime(date_to, DATETIME_FORMAT) timedelta = to_dt - from_dt diff_day = timedelta.days + float(timedelta.seconds) / 86400 return diff_day
# 得到的是天数,若要不足一天按一天算,加上 diff_day=round(math.floor(diff_day))+1
2.计算两个时间点的时间差,用"%Y-%m-%d %H:%M:%S"表示
3.解决与格林威治时间的时间差问题