2016-10-27 2 views
0

시작 시간에 최소 시간을 추가하는 것을 기반으로 새로운 변수 AUTOMATIC_END_TIME을 만들 수있는 방법을 찾으려고하는데, START_TIME을 시간으로 변환하여 시간을 추가 할 수있는 방법을 찾아보십시오.HH : MM 가변 시간 문자열에 x 초의 시간 가치 추가

지금까지 내 스크립트는 다음과 같습니다

from time import sleep 
from datetime import datetime, timedelta 

START_TIME = "19:18" 
END_TIME = "19:25" 

LOGA = ["one", "two"] 

TIME_DIFFERENCE = datetime.strptime(END_TIME, "%H:%M") - datetime.strptime(START_TIME, "%H:%M") 
TIME_DIFFERENCE = TIME_DIFFERENCE.seconds 

if len(LOGA) * (60 * (5 + 1)) >= TIME_DIFFERENCE: 
    print "Show minimum end time" 
    AUTOMATIC_END_TIME = "" # Should come out as 19:30 

현재 스크립트가되어야하는 모든 AUTOMATIC_END_TIME을 제외하고 변경하지 마십시오을 START_TIME + (60 * (5 + 1)19:30

답변

2
>>> (datetime.strptime(START_TIME, "%H:%M") + timedelta(minutes=12)).strftime('%H:%M') 
'19:30' 
1
from time import sleep 
from datetime import datetime, timedelta 

START_TIME = "19:18" 
END_TIME = "19:25" 

LOGA = ["one", "two"] 

TIME_DIFFERENCE = datetime.strptime(END_TIME, "%H:%M") - datetime.strptime(START_TIME, "%H:%M") 
TIME_DIFFERENCE = TIME_DIFFERENCE.seconds 

if len(LOGA) * (60 * (5 + 1)) >= TIME_DIFFERENCE: 
    print "Show minimum end time" 
    AUTOMATIC_END_TIME = (datetime.strptime(START_TIME, "%H:%M") + timedelta(minutes=12)).strftime('%H:%M') 
    print AUTOMATIC_END_TIME 
로 나올한다
관련 문제