utils/tools/time_handle.py

22 lines
539 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
# @Time : 2023/5/19 10:14
# @Author : chenyinhua
# @File : time_handle.py
# @Software: PyCharm
# @Desc:
# 标准库导入
import time
def timestamp_strftime(timestamp, style="%Y-%m-%d %H:%M:%S"):
"""
将时间戳转换为指定格式日期
"""
try:
if isinstance(timestamp, str):
timestamp = eval(timestamp)
return time.strftime(style, time.localtime(float(timestamp / 1000)))
except Exception as e:
return f"timestamp或者style格式错误{e}"