Skip to content

Instantly share code, notes, and snippets.

@remino
Created August 2, 2014 01:09
Show Gist options
  • Save remino/40b74d79ad79bd886eaa to your computer and use it in GitHub Desktop.
Save remino/40b74d79ad79bd886eaa 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'))
@remino
Copy link
Author

remino commented Aug 2, 2014

That said, you might as well write this:

print(datetime.now().strftime('%Y-%m-%d %H:%M:%S +0900'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment