Discuss / Python / 代码

代码

Topic source

pipi-hongwy

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

def to_timestamp(dt_str, tz_str):

    t1=datetime.strptime(dt_str,'%Y-%m-%d %H:%M:%S')  

    tz=re.match(r'UTC([+|-]\d{1,2}):00',tz_str).group(1)  

    tz_utc= timezone(timedelta(hours=int(tz)))

    t2 = t1.replace(tzinfo=tz_utc)

    return t2.timestamp()


  • 1

Reply