Discuss / Python / 交作业

交作业

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()

```

```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

Reply