Discuss / Python / datetime

datetime

Topic source

Mr_RightMen

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

  • 1

Reply