python - How set timer for tomorrow 10 AM -
i tried suggestions other answers similar question (https://stackoverflow.com/a/2031297/940208) , have far is:
t = datetime.datetime.today() tomorrow = datetime.datetime(t.year,t.month,t.day+1,10,0)
the problem is, when have last day of month fail:
valueerror: day out of range month
so how can rewrite statement (without wrapping if condition trying find last day) include such situation?
another question - timezone of such timer , how can work on current (system) timezone?
use datetime.datetime.replace
, datetime.timedelta
:
tomorrow = t.replace(hour=10, minute=0, second=0, microsecond=0) + \ datetime.timedelta(days=1)
alternatives:
tomorrow = datetime.datetime.combine(t.date(), datetime.time(10)) + \ datetime.timedelta(days=1) tomorrow = datetime.datetime(t.year, t.month, t.day, 10) + \ datetime.timedelta(days=1)
Comments
Post a Comment