Last active
November 29, 2021 05:46
-
-
Save yangyang5214/2eee66830b58b050eaa270a4035ab2fc to your computer and use it in GitHub Desktop.
[utc时间转本地时区] #datetime #python
This file contains hidden or 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
def utc_to_shanghai(date: str): | |
""" | |
utc 转 shanghai 时区 | |
:param date: | |
:return: | |
""" | |
import time | |
import pytz | |
import datetime | |
timestamp = time.mktime(time.strptime(date, '%Y-%m-%dT%H:%M:%SZ')) | |
return datetime.datetime.fromtimestamp(timestamp).astimezone(pytz.timezone("UTC")).strftime('%Y-%m-%d %H:%M:%S') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment