import typing as t
import time
import datetime
"""
原文:
python时间相互转换
https://py-code.readthedocs.io/zh/latest/Python/time_utils/index.html
"""
"""
# 1.1. 时间字符串转换为13位时间戳
# 1.2. 时间字符串转换为datetime
# 1.3. 时间戳转换为时间字符串
# 1.4. 时间戳转换为datetime对象
# 1.5. datetime对象转换为时间字符串
# 1.6. datetime对象转换为13位时间戳
"""
# 1.1. 时间字符串转换为13位时间戳
def str_to_timestamp(str_time: str, time_format: str = "%Y-%m-%d %H:%M:%S") -> int:
"""
时间字符串转换为13位时间戳
:param str_time: 时间字符串
:param time_format: 时间字符串格式 default: %Y-%m-%d %H:%M:%S
example: %Y-%m-%d
:return: 13位时间戳
Usage::
>>> str_to_timestamp("2022-10-10", "%Y-%m-%d")
1665331200000
>>> str_to_timestamp("2022-10-10 10:10:10")
1665367810000
"""
try:
time_array = time.strptime(str_time, time_format)
return int(time.mk
Python 时间和时间戳相互转换
最新推荐文章于 2024-10-21 11:08:46 发布