Skip to content

Instantly share code, notes, and snippets.

@dixudx
Forked from remino/jstnow.py
Created November 22, 2017 06:49
Show Gist options
  • Save dixudx/e05736013d8b180ffb1a5ae748b5c27f to your computer and use it in GitHub Desktop.
Save dixudx/e05736013d8b180ffb1a5ae748b5c27f to your computer and use it in GitHub Desktop.
Python: Print date & time in JST time zone without pytz module
# 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