我想把utc时间转换为北京时间
问题相关代码
import time
utc_time = "2022-01-19T11:10:04Z"
# 第一次替换为空格,第二次替换为空字符串
utc_time = utc_time.replace("T", " ").replace("Z","")
utc_time = time.strptime(utc_time, "%Y-%m-%d %H:%M:%S")
utc_time = time.mktime(utc_time)
beijing_time = utc_time + 8*60*60
new_time = time.strftime('%Y-%m-%d %H:%M:%S', beijing_time)
运行结果及报错内容
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_26148/3214172633.py in <module>
6 utc_time = time.mktime(utc_time)
7 beijing_time = utc_time + 8*60*60
----> 8 new_time = time.strftime('%Y-%m-%d %H:%M:%S', beijing_time)
TypeError: Tuple or struct_time argument required