交作业
Topic source```python
def to_timestamp(dt_str, tz_str):
cday=datetime.strptime(dt_str,"%Y-%m-%d %H:%M:%S")
t=re.match(r'UTC(.*):.*',tz_str).group(1)
time=int(t)
tz=timezone(timedelta(hours=time))
localtime=cday.replace(tzinfo=tz)
#这个没必要,只要绑定时区timestamp就是对的realtime=localtime.astimezone(timezone.utc)
return localtime.timestamp()
```
还是用自带的好了…
def to_timestamp(dt_str, tz_str):
cday=datetime.strptime(dt_str,"%Y-%m-%d %H:%M:%S")
t=re.match(r'UTC(.*):.*',tz_str).group(1)
time=int(t)
tz=timezone(timedelta(hours=time))
localtime=cday.replace(tzinfo=tz)
#这个没必要,只要绑定时区timestamp就是对的realtime=localtime.astimezone(timezone.utc)
return localtime.timestamp()
- 1
用户5824048131
正则表达式写的比较烂
```python
def to_timestamp(dt_str, tz_str):
cday=datetime.strptime(dt_str,"%Y-%m-%d %H:%M:%S")
t=re.match(r'UTC(.*):.*',tz_str).group(1)
time=int(t)
tz=timezone(timedelta(hours=time))
localtime=cday.replace(tzinfo=tz)
#这个没必要,只要绑定时区timestamp就是对的realtime=localtime.astimezone(timezone.utc)
return localtime.timestamp()
```