Discuss / Python / 很多同学上一章正则表达式没学到位呀

很多同学上一章正则表达式没学到位呀

Topic source

def to_timestamp(dt_str, tz_str):

    dt_cform = datetime.strptime(dt_str,'%Y-%m-%d %H:%M:%S') #datetime 格式化

    tz_value = int(re.match(r'UTC\+?([\-\d]+):',tz_str).group(1)) #match 获取时区转化为数字,re.compile只拿负号,不要加号

    tz_delta = timezone(timedelta(hours=tz_value)) #时区差

    dt_currunt = dt_cform.replace(tzinfo=tz_delta) #当地时间

    return dt_currunt.timestamp() #转timestamp

你这个时区的分钟没有拿到啊,忽略了时区的分钟


  • 1

Reply