【发布时间】:2016-12-01 09:39:34
【问题描述】:
我必须在 Python 中以天为单位计算两个日期之间的时间,但没有 datetime 模块。
我设法在没有datetime 的情况下解析日期:
def date(error):
global sdate
if error:
print(sdate," isn't a valable date ! ")
sdate = input('Date : ')
try:
ldate = sdate.split('.')
ldate = [ int(x) for x in ldate]
day,month,year = ldate
except ValueError:
date(True)
if year%4==0 and year%100!=0 or year%400==0:
bis = True
else:
bis = False
if month not in range(1,13):
date(True)
if month not in(1,3,5,7,8,10,12):
mmax = 31
elif month in(4,6,9,11):
mmax = 30
elif month == 2 and bis == True:
mmax = 29
elif month == 2 and bis == False:
mmax = 28
if day not in range(1,mmax+1):
date(True)
date(None)
print(ldate)
但不知道如何获取日期之间的时间。
最简单的方法是什么?
谢谢, 布拉索
PS:这根本不是家庭作业,我需要它用于个人项目,在那里我使用任何太容易生活的模块;)
【问题讨论】:
-
如果你避开
datetime,这既不容易也不是Pythonic。 -
尝试提供一些示例代码。到目前为止,您尝试过什么?
-
我会尽快修改问题
-
请格式化您的代码并发布。没有适当的缩进。
标签: python date datetime module days