简体   繁体   English

如何在 Python 中实现 Act / Act 约定?

[英]How can I realize Act / Act Convention in Python?

If there are two given dates(eg, from Oct 12, 2016 to Nov 21, 2019).如果有两个给定日期(例如,从 2016 年 10 月 12 日到 2019 年 11 月 21 日)。 Based on the Act/Act Convention, how can I calculate the amount of days by the "While" or "IF" loop?根据法案/法案公约,如何通过“While”或“IF”循环计算天数?

You can use datetime module, ie:您可以使用datetime模块,即:

from datetime import datetime

df = "%b %d, %Y"
start = datetime.strptime('Oct 12, 2016', df)
end = datetime.strptime('Nov 21, 2019', df)
diff = end - start
print (diff.days)
# 1135

Demo演示

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

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