Discuss / Python / 1

bai渡者

#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') tz=re.split(r'''[UTC:00]''', tz_str) if tz[3]=='-': tz=-int(tz[4]) elif tz[3] =='+': tz = int(tz[4]) else: tz=int(tz[3]) tzutc = timezone(timedelta(hours=tz)) dt=dt.replace(tzinfo=tzutc) dt=dt.timestamp() return dt


  • 1

Reply