Created
August 2, 2014 01:09
-
-
Save remino/40b74d79ad79bd886eaa to your computer and use it in GitHub Desktop.
Python: Print date & time in JST time zone without pytz module
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
# Print date & time in JST time zone | |
# For Python 2.7.x without pytz module | |
import datetime | |
from datetime import datetime, timedelta, tzinfo | |
class JST(tzinfo): | |
def utcoffset(self, dt): | |
return timedelta(hours=9) | |
def tzname(self, dt): | |
return "JST" | |
def dst(self, dt): | |
return timedelta(hours=0) | |
print(datetime.now().replace(tzinfo=JST()).strftime('%Y-%m-%d %H:%M:%S %z')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That said, you might as well write this: