Discuss / Python / 交作业

交作业

Topic source

Alvin天枭

#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_m=re.match(r'^UTC(.\d+):(\d+)$',tz_str) tz=int(tz_m[1]) in_dt=dt.replace(tzinfo=timezone(timedelta(hours=tz))) utc_dt=in_dt.astimezone(timezone(timedelta(hours=0))) return utc_dt.timestamp()

Alvin天枭

#2 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_m=re.match(r'^UTC(.\d+):(\d+)$',tz_str) tz=int(tz_m[1]) in_dt=dt.replace(tzinfo=timezone(timedelta(hours=tz)))

#utc_dt=in_dt.astimezone(timezone(timedelta(hours=0)))
#return utc_dt.timestamp()
return in_dt.timestamp()

  • 1

Reply