Created
July 11, 2018 03:28
-
-
Save FGtatsuro/7865e5bd44d63a2a56f1bb0701fd5cad to your computer and use it in GitHub Desktop.
時刻の扱い
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# FYI: https://gist.github.com/FGtatsuro/06387542af093d98ef5b | |
import datetime | |
# timezone=utcのawareオブジェクトを基準にする | |
time_info = datetime.datetime.now(tz=datetime.timezone.utc) | |
print(time_info) | |
# ローカライズしたawareオブジェクト | |
# 夏時間その他を扱う必要がなければこれで十分 | |
# ちゃんと扱うならばpytz(https://pypi.org/project/pytz/) 使った方が良いか | |
jst = datetime.timezone(offset=datetime.timedelta(hours=9), name='jst') | |
time_info_jst = time_info.astimezone(tz=jst) | |
print(time_info_jst) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment