LoginSignup
2
1

More than 3 years have passed since last update.

PythonAnywhereとtime zone設定

Posted at

はじめに

本記事はボートレース予測Webサイトを立ち上げた際に発覚した事象です。
きょう、ていの良い予想はあたるだろうか

そういえば、datetimeをどの地域で取得するかって、今まで意識したことなかったなあと思い記事にしました。

結論

何気なく使用するtimeやdatetimeですが、指定せずにpythonanywhere上にて実行するとUTC時刻が取得されてしまいます。(日本にいる前提だと9時間前の時刻が取得されてしまう。)

以下のように設定すれば大丈夫です。

app.py(抜粋)
import os
import time

os.environ["TZ"] = "Asia/Tokyo"
time.tzset()
tday=datetime.date.today()

公式でもかかれておりました。
https://help.pythonanywhere.com/pages/SettingTheTimezone/

できごと

日付が変わったタイミングでWebページ上の日付が変わることを期待していたら変わらず..上記の対応で解決しました。

image.png

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1