Created
February 2, 2018 03:06
-
-
Save yuhr123/fd2118e3ba57f6470aea7ddec6d34413 to your computer and use it in GitHub Desktop.
Python datatime 模块按时区打印时间
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
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