Discuss / Python / 系统已经知道了自身是UTC+8啊。。

系统已经知道了自身是UTC+8啊。。

Topic source

aertawergtxcv

#1 Created at ... [Delete] [Delete and Lock User]
    dt=datetime.strptime(dt_str,'%Y-%m-%d %H:%M:%S')
    utc=re.match(r'^(UTC)(\+[0-9]+|\-[0-9]+)(\:00)$',tz_str).group(2)
    x=8-int(utc)
    dt=dt+timedelta(hours=x)
    ts=dt.timestamp()
    return ts

因为系统知道自身时区是UTC+8,因此在timestamp运算中自动把UTC+8矫正了,因此要把输入的时间变为UTC+8时间,而不是直接变为UTC时间。


  • 1

Reply