Discuss / Python / timezone convert

timezone convert

Topic source

在路上Ce

#1 Created at ... [Delete] [Delete and Lock User]
def to_timestamp(dr_str, tz_str):
    dt = datetime.strptime(dr_str, '%Y-%m-%d %H:%M:%S')
    tz = int(re.match('^UTC(\+|\-\d+).*', tz_str).group(1))
    tzone = timezone(timedelta(hours=tz))
    return dt.replace(tzinfo=tzone).timestamp()

right-chen

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

运行报错了


  • 1

Reply