Discuss / Python / datetime作业

datetime作业

Topic source

def to_timestamp(dt_str, tz_str):

    dt=datetime.strptime(dt_str,'%Y-%m-%d %H:%M:%S')

    tz=int(re.match(r'UTC((\+|\-)\d+):\d\d',tz_str).group(1))  

    tz1=timezone(timedelta(hours=tz))

    t=dt.replace(tzinfo=tz1)

    a=t.timestamp()

    return a


  • 1

Reply