lost and found ( for me ? )

Python pytz : convert time to UTC from JST

small tips. Here is how to convert to UTC from JST

install pytz module via yum
# yum search pytz
pytz.noarch : World Timezone Definitions for Python

# yum install pytz –y

UTC
>>> now = datetime.now(pytz.utc)
>>> now
datetime.datetime(2014, 8, 17, 5, 10, 3, 332357, tzinfo=<UTC>)

JST
>>> now.astimezone(pytz.timezone('Asia/Tokyo'))
datetime.datetime(2014, 8, 17, 14, 10, 3, 332357, tzinfo=<DstTzInfo 'Asia/Tokyo' JST+9:00:00 STD>)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.