Discuss / Python / 练习答案

练习答案

Topic source

zx_sunrise

#1 Created at ... [Delete] [Delete and Lock User]
def to_timestamp(dt_str, tz_str):
    m = re.match(r'\w+([+\-])(\d{1,2}):(\d{1,2})', tz_str)
    s = '{0}{1[0]}{1[1]:0>2s}:{1[2]:0>2s}'.format(dt_str, m.groups())
    return datetime.strptime(s, '%Y-%m-%d %H:%M:%S%z').timestamp()

zx_sunrise

#2 Created at ... [Delete] [Delete and Lock User]
def to_timestamp(dt_str, tz_str):
    g = re.search(r'([+\-])(\d{1,2}):(\d{1,2})', tz_str).groups()
    return datetime.strptime(f'{dt_str}{g[0]}{g[1]:0>2s}:{g[2]:0>2s}', '%Y-%m-%d %H:%M:%S%z').timestamp()

简化一下


  • 1

Reply