-
-
Save dixudx/e05736013d8b180ffb1a5ae748b5c27f 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