Discuss / Python / 作业

作业

Topic source

def to_timestamp(dt_str, tz_str):

    # str2datetime

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

    # read user time zone   

    h = re.match(r'UTC(.*):',tz_str)

    hour = int(h.group(1))

    # replace time zone

    tz_user = timezone(timedelta(hours = hour))

    user_dt = my_dt.replace(tzinfo = tz_user)

    return user_dt.timestamp()


  • 1

Reply