问题
How do you print the time with specific timezone used by APScheduler. I used an specific timezone for its BackgroundScheduler. When I used the 'cron' job to do a task on a specific time, it didn't went well. My suspicion is it's using a different time.
from flask import Flask
from datetime import datetime
from oauth2client.service_account import ServiceAccountCredentials
from mysql.connector import Error
from threading import Thread
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor
import datetime
import time
import gspread
import mysql.connector
app = Flask(__name__)
executors = {
'default': ThreadPoolExecutor(16),
'processpool': ProcessPoolExecutor(4)
}
sched = BackgroundScheduler(timezone='Asia/Seoul', executors=executors)
def job_1():
print("YES.")
def job_2():
print("I'm working working...")
print(datetime.datetime.now())
sched.add_job(job_1, 'cron', hour=17, minute=19)
sched.add_job(job_2, 'interval', seconds=10)
@app.route('/')
def homepage():
return '<h1>Hello World!</h1>'
if __name__ == '__main__':
sched.start()
app.run(debug=True, use_reloader=False)
I needed to run job_1 on 5:19 on my Computer, but I guess I specified a timezone for APScheduler, so it did not execute. I want to know the current time the APSCheduler is using.
UPDATE: When I used timezone=None,
sched = BackgroundScheduler(timezone=None, executors=executors)
It went well, it followed the time on my Computer. Now I just want to print the time of the specified timezone I used in there.
来源:https://stackoverflow.com/questions/52074191/print-time-on-apscheduler