Discuss / Python / 作业,合理使用正则表达式更好

作业,合理使用正则表达式更好

Topic source

小羊飞的

#1 Created at ... [Delete] [Delete and Lock User]

def to_timestamp(dt_str, tz_str): dt = datetime.strptime(dt_str,'%Y-%m-%d %H:%M:%S') hz = int(re.match(r'^UTC([+|-]\d{1,2}):\d{2}$',tz_str).group(1)) dtzone = dt.replace(tzinfo=timezone(timedelta(hours=hz))) print(dtzone) return dtzone.timestamp()


  • 1

Reply