Discuss / Python / 打卡

打卡

Topic source

def to_timestamp(dt_str, tz_str):

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

    tz = int(re.match(r'.+?([+-]\d+)', tz_str).group(1))

    now = now.replace(tzinfo = timezone(timedelta(hours=tz)))

    return now.timestamp()


  • 1

Reply