要将string类型的timestamp转换为yyyy-MM-dd HH:mm:ss格式的日期和时间,您可以使用以下代码:

from datetime import datetime

timestamp = "1633000000"  # 假设timestamp为字符串类型的时间戳

# 将字符串类型的时间戳转换为整数类型
timestamp = int(timestamp)

# 将整数类型的时间戳转换为datetime对象
dt_object = datetime.fromtimestamp(timestamp)

# 将datetime对象格式化为指定的字符串格式
formatted_datetime = dt_object.strftime("%Y-%m-%d %H:%M:%S")

print(formatted_datetime)

这样,您就可以将string类型的timestamp转换为yyyy-MM-dd HH:mm:ss格式的日期和时间。


原文地址: https://www.cveoy.top/t/topic/pqVE 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录