Discuss / Python / 练习

练习

Topic source

svcasvawe

#1 Created at ... [Delete] [Delete and Lock User]
import re
from datetime import datetime, timezone, timedelta

def to_timestamp(dt_str, tz_str):
    cday = datetime.strptime(dt_str, '%Y-%m-%d %H:%M:%S')
    r = re.compile(r'^UTC(\+|\-)(\d{1,2}):(\d{2})$')
    utc = r.match(tz_str)
    print(utc.group(1))
    if utc.group(1) == '+':
        print(cday.timestamp()+(8-int(utc.group(2)))*3600)
    elif  utc.group(1) == '-':
        print(cday.timestamp()+(int(utc.group(2))-8)*3600)

t1 = to_timestamp('2015-6-1 08:10:30','UTC-9:00' )

  • 1

Reply