의 값에 의해이 시점 (매월 초)을 찾을 수있는 방법입니다 11월 2016 년의 1 일 자정에있다
한 시간에 3600 초가 있습니다. 따라서, 게임 시간은 항상 곱한 경과 '실시간'(timedelta)는 3600
import datetime
def time_shift(t1, t2):
'''returns the game-time timedelta based on two 'real' datetime objects'''
real_elapsed = t2 - t1
game_elapsed = real_elapsed * 3600
return game_elapsed
예 :
>>> t1 = datetime.datetime(year=2016, month=10, day=26)
>>> delta = datetime.timedelta(seconds=30)
#lets say 30 seconds realtime passes
#that should be 1 day 6 hours game-time.
>>> t2 = t1 + delta
>>> time_shift(t1, t2)
datetime.timedelta(1, 21600) #1 day, 21600 seconds IE 1 day and 6 hours
#You can translate that to a specific date for the game, too
>>> game_date = t1 + time_shift(t1, t2)
>>> game_date
datetime.datetime(2016, 10, 27, 6, 0)
당신이 다음 달 1 일까지의 시간을 얻고 싶다면 . 우리는 다음과 같이 할 수 있습니다. 나는 우리가 이미/대신 시도의 current_datetime
cur_month, cur_year = current_datetime.month, current_datetime.year
try:
next_month = datetime.datetime(year=cur_year, month=cur_month+1, day=1)
except ValueError:
#If it was december
next_month = datetime.datetime(year=cur_year+1, month=1, day=1)
until_next_month = next_month - current_datetime
로 게임 현재 날짜/시간을 가정합니다 그럴 수 단순히 테스트 if cur_month != 12
또는
from dateutil.relativedelta import relativedelta
def next_month(current_datetime):
return (current_datetime + relativedelta(months=1)).replace(day=1, hour=0, minute=0, second=0)
def hours_until(dt1, dt2):
delta = dt2 - dt1
hours = (delta.hours * 24) + (delta.seconds/3600)
return hours
월 값 '% m'이 (가) 이전 값에서 변경되면 새 달을 입력했습니다. –