from typing import Union
from datetime import datetime


def stamp2time(stamp_val: Union[int, float, str]) -> datetime:
    """
    解析time stamp时间戳到datetime类型
    Args:
        stamp_val: 年月日时间字符串, eg: 1583985504763
    Returns:
        datetime
    """

    left, *right = str(stamp_val).split(".")
    dot_right = "".join(right)
    left_, right_ = left[:10], left[10:]
    stamp_val = float(f"{left_}.{right_}{dot_right}")
    return datetime.fromtimestamp(stamp_val)