Skip to content

Instantly share code, notes, and snippets.

@xianghuzhao
Last active January 10, 2017 03:44
Show Gist options
  • Save xianghuzhao/3081815edff0dfe6754e5a16e987af3e to your computer and use it in GitHub Desktop.
Save xianghuzhao/3081815edff0dfe6754e5a16e987af3e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import time
def time_zone(t):
if t.tm_isdst == 1 and time.daylight == 1:
tz_sec = time.altzone
tz_name = time.tzname[1]
else:
tz_sec = time.timezone
tz_name = time.tzname[0]
if tz_sec > 0:
tz_sign = '-'
else:
tz_sign = '+'
tz_offset = '%s%02d%02d' % (tz_sign, abs(tz_sec)//3600, abs(tz_sec//60)%60)
return (tz_offset, tz_name)
if __name__ == '__main__':
t = time.localtime()
time_str = time.strftime('%Y-%m-%d %H:%M:%S', t)
print('%s %s %s' % ((time_str,) + time_zone(t)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment