2016-12-01 6 views
-1

파이썬에서 일요일에 두 날짜 사이의 시간을 계산해야하지만 datetime 모듈을 사용하지 않아야합니다.(도움이 필요합니다.) Dateti가없는 두 날짜 사이의 시간

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) 

을하지만 날짜 사이의 시간을 얻는 방법을 알아낼하지 않았다 :

나는 datetime하지 않고 날짜를 구문 분석 할 수 있었다.

가장 쉬운 방법은 무엇입니까?

감사합니다, Blaxou

PS :;

+3

'datetime'을 피한다면, 그것은 쉽지 않을 것입니다. – TigerhawkT3

+0

몇 가지 샘플 코드를 사용해보십시오. 이 시점까지 무엇을 시도 했습니까? –

+0

곧 질문을 수정하겠습니다. – Blaxou

답변

1

당신은해야합니다) 그것은 전혀 숙제 아니다, 나는 내가 너무 쉽게 삶을 만드는 모듈 중 하나를 사용하여 개인 프로젝트를 위해 필요 두 날짜의 차이를 확인하는 것보다 훨씬 더 많은 일을하십시오.

나는 이것을 작성하기 위해 의사 코드를 제공 할 것이므로 자신의 프로그램을 작성하십시오.

• get the dates 
• validate the dates 
    -> (ex. It should be false for feb 29 2007) 
• calculate total number of days of that particular year for both dates 
    -> (ex 1 jan 2015 = 01 and 28 feb 2016 = 59) 
• calculate the year difference 
• calculate number of leap years between two days (excluding both end) 
    -> (2004 and 2008 leap year is 0) 
• calculate the difference by 
    diff(number of days) + (year difference * 365) + number of leap years 
+0

숙제가 아님, 내 게시물을 편집했습니다.) – Blaxou

+0

너무 길기 때문에 프로그램을 작성할 수 없습니다. – Prajwal

+0

프로그램을 작성하는 것이 아니라 단지 정밀도였습니다.) – Blaxou