I'm trying to run a job ever day at 8:00 AM at timezone('Asia/Calcutta'), so i started using python scheduler. sample snippet
import schedule
import time
def job(t):
print "I'm working...", t
return
schedule.every().day.at("08:00").do(job,'It is 08:00')
while True:
schedule.run_pending()
time.sleep(30) # wait one minute
this snippets works very well if a execute in Indian servers, but if i run in COLAB or AWS (which are in different timezone), job start at 8:00 am based on that particular time zone. But i would like to make code to run every day 8:00 am on this timezone('Asia/Calcutta'), irrespective of the server time zone. i gone through different article from stackoverflow related to timezones, getting offset and changing 8:00 am to something like 8:00 + some offset 4:30 hrs. but did notwork.
looking for best way to run python code on anyserver/any timezone, but scheduler will trigger in timezone('Asia/Calcutta') this timezon.
is there any way to change datetime timezone on thread level or full python process level (only for that script/thread, not system level), so i want to change timezone once in python, and after that where every i call datetime.now(), it should give time as per new timzone,
eastern = timezone('Asia/Calcutta') # naive datetime naive_dt = datetime.now() # localized datetime loc_dt = datetime.now(eastern) print(naive_dt.strftime(fmt)) print(loc_dt.strftime(fmt))
based on this (answer) not interested to change system files, looking pythonic way