Discuss / Python / 作业

作业

Topic source

东东男装

#1 Created at ... [Delete] [Delete and Lock User]
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
from datetime import datetime,timezone,timedelta
def to_timestamp(dt_str,tz_str):
    m = re.match(r'^UTC([+|-])(0?[0-9]|1[0-2])\:00$',tz_str)
    s = int(m.group(1) + m.group(2))
    dt_dt = datetime.strptime(dt_str,'%Y-%m-%d %H:%M:%S')
    dt_utc_7 = timezone(timedelta(hours=s))
    dt = dt_dt.replace(tzinfo=dt_utc_7)
    return dt.timestamp()

t1 = '2015-05-31 16:10:30'
t2 = 'UTC-09:00'


print(to_timestamp(t1,t2))

  • 1

Reply