Help us understand the problem. What is going on with this article?

GoogleAppEngineで日本時間(JST)を使う

More than 3 years have passed since last update.

GoogleAppEngine上で Python + Flask + SQLAlchemy で開発しているが
タイムゾーンがUTCなので、datetime.nowが JSTとずれてしまう。
対応してみたのメモ

pytzを入れる

requirements.txt
Flask==0.12.1
Flask-SQLAlchemy==2.2
pytz
$ pip install -t lib -r requirements.txt

datetime.nowでタイムゾーンを指定する

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import pytz
import datetime

app = Flask(__name__)
db = SQLAlchemy(app)

class Hoge(db.Model):
     __tablename__ = 'hoge'
     id = db.Column(db.Integer, primary_key=True)
     created_at = db.Column(db.DateTime, default=datetime.datetime.now(pytz.timezone('Asia/Tokyo'))

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away