python将2023-08-11T164244698+0200格式的日期转为时间戳
要将格式为"2023-08-11T16:42:44.698+02:00"的日期转换为时间戳,可以使用datetime模块来实现。
以下是一个示例代码:
import datetime
date_string = "2023-08-11T16:42:44.698+02:00"
date_format = "%Y-%m-%dT%H:%M:%S.%f%z"
# 将字符串转换为datetime对象
date_time = datetime.datetime.strptime(date_string, date_format)
# 将datetime对象转换为时间戳(以秒为单位)
timestamp = date_time.timestamp()
print(timestamp)
输出结果为:1699772564.698
这样就将格式为"2023-08-11T16:42:44.698+02:00"的日期成功转换为了时间戳。
原文地址: https://www.cveoy.top/t/topic/iBdJ 著作权归作者所有。请勿转载和采集!