Skip to content

Instantly share code, notes, and snippets.

@yangyang5214
Last active November 29, 2021 05:46
Show Gist options
  • Save yangyang5214/2eee66830b58b050eaa270a4035ab2fc to your computer and use it in GitHub Desktop.
Save yangyang5214/2eee66830b58b050eaa270a4035ab2fc to your computer and use it in GitHub Desktop.
[utc时间转本地时区] #datetime #python
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