简体   繁体   English

如何以天为单位获得两个时间戳之间的差异?

[英]How to get the difference between two timestamps in days?

How to get the difference between two timestamps in days?如何以天为单位获得两个时间戳之间的差异?

  "min": 1487344607000,
  "max": 1492442207000,

Here is a quick example,这是一个简单的例子,

import datetime

min = min/1000           #removing milli seconds
max = max/1000

min = datetime.datetime.fromtimestamp(min)
max = datetime.datetime.fromtimestamp(max)

print("Total Days : " + str((max-min).days))

There are 2 interpretations:有2种解释:

import datetime
date1=datetime.datetime.fromtimestamp(min/1000)
date2=datetime.datetime.fromtimestamp(max/1000)
delta = date2-date1
days = delta.days

Or if the difference must be a full day:或者,如果差异必须是一整天:

days=(max-min)/86400

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM