Created
January 11, 2016 11:47
-
-
Save suzuki-shunsuke/2624f726458b7e27a617 to your computer and use it in GitHub Desktop.
datetimeのロケールの操作
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
import datetime | |
import pytz | |
# ロケールのないdatetimeにロケール情報を与える | |
d = datetime.datetime.now() # naiveなローカルな時刻を取得 | |
d2 = pytz.timezone("Asia/Tokyo").localize(d) | |
# ロケールを変更する | |
d3 = d2.astimezone(pytz.utc) | |
# awareなdatetimeオブジェクトからnaiveなdatetimeオブジェクトを取得する | |
d2.replace(tzinfo=None) | |
d4 = datetime.datetime.utcnow() # naiveなUTC時刻を取得 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment