Discuss / Python / 作业

作业

Topic source

posroachips

#1 Created at ... [Delete] [Delete and Lock User]
def to_timestamp(dt_str, tz_str):
    re_tz = r'^(UTC)([\+-]\d{1,2})\:(00)$'
    tz = int(re.match(re_tz, tz_str).group(2))
    dt = datetime.strptime(dt_str, '%Y-%m-%d %H:%M:%S')
    tz = timezone(timedelta(hours=tz))
    dt = dt.replace(tzinfo=tz)
    return dt.timestamp()

  • 1

Reply