Skip to content

Instantly share code, notes, and snippets.

@yuhr123
Created February 2, 2018 03:06
Show Gist options
  • Save yuhr123/fd2118e3ba57f6470aea7ddec6d34413 to your computer and use it in GitHub Desktop.
Save yuhr123/fd2118e3ba57f6470aea7ddec6d34413 to your computer and use it in GitHub Desktop.
Python datatime 模块按时区打印时间
from datetime import datetime, timedelta, timezone
# 东8区时间
time_utc_8 = datetime.now().astimezone(timezone(timedelta(hours=8)))
print(time_utc_8)
# 2018-02-02 10:56:10.496695+08:00
# 格式化
format = time_utc_8.strftime('%Y-%m-%d %H:%M:%S')
print(format)
# '2018-02-02 10:56:10'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment