from datetime import datetime def ts_cover_str(ts=0, _format='%Y-%m-%d %H:%M:%S') -> str: return datetime.fromtimestamp(ts / 1000).strftime(_format) def str_cover_date(s: str, _format='%Y-%m-%d %H:%M:%S') -> datetime: return datetime.strptime(s, _format) def timestamp_convert(ts: int) -> str: return seconds_convert(ts // 1000) def seconds_convert(seconds: int) -> str: hours = seconds // 3600 minutes = (seconds % 3600) // 60 seconds = seconds % 60 s = "" if hours > 0: s = f"{s} {hours}小时" if minutes > 0: s = f"{s} {minutes}分" if seconds > 0: s = f"{s} {seconds}秒" return s def date_convert_dt_hh(date_str: str, _format='%Y-%m-%d %H:%M:%S') -> str: date_obj = datetime.strptime(date_str, _format) return date_obj.strftime('%Y%m%d%H')