1117|datetime 模块

http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001431937554888869fb52b812243dda6103214cd61d0c2000

re.match
match :只从字符串的开始与正则表达式匹配,匹配成功返回matchobject,否则返回None;

作业:

from datetime import datetime,timedelta
import re

def to_timestamp(dt_str, tz_str):
    #获取时区数字
    tz_num = re.match(r'^(\w{3})[\+|\-](\d+)\:(00)$',tz_str)
    tzn = int(tz_num.group(2))
    print (tzn)
    #获取输入的当地时间
    cday = datetime.strptime(dt_str, '%Y-%m-%d %H:%M:%S')
    print ('cday is:',cday)
    utctime = cday - timedelta(hours = tzn)
    print ('utctime is: ',utctime)

    print (utctime.timestamp())

t1 = to_timestamp('2015-6-1 08:10:30', 'UTC+7:00')
t2 = to_timestamp('2015-5-31 16:10:30', 'UTC-09:00')

你可能感兴趣的:(1117|datetime 模块)