开发者

Rounding the duration of two date values

I have two date values in Python which Im trying to get a rounded duration from.

For example: 01-01-2000 to 12-31-2099 is really "100 years", not "99 years".

I have an example, in Java, but Im not sure how to port this to Python speak:

round(endDateEpochInMilliseconds -startDateEpochInMilliseconds /(365.25 * 24 * 3600 * 1000))
开发者_C百科

Im sure something similar is doable in Python.


import datetime

date1 = datetime.date(2000,1,1)
date2 = datetime.date(2099, 12, 31)

delta = date2-date1

print round(delta.days/365.25,0)


You defently must put endDateEpochInMilliseconds -startDateEpochInMilliseconds into brackets!

round( (endDateEpochInMilliseconds -startDateEpochInMilliseconds) /(365.25 * 24 * 3600 * 1000))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜