Discuss / Python / 小练习学习

小练习学习

Topic source

from datetime import datetime,timezone,timedelta

def to_timestamp(dt_str,tz_str): dt=datetime.strptime(dt_str,'%Y-%m-%d %H:%M:%S') n=int(re.match(r'^UTC([+-]\d+):00$',tz_str).group(1)) tz_utc=timezone(timedelta(hours=n)) dt=dt.replace(tzinfo=tz_utc) d=dt.timestamp() print('%s==>%f'%(dt_str,d))

if name=='main': to_timestamp('2015-6-1 08:10:30','UTC+7:00') to_timestamp('2015-5-31 16:10:30','UTC-09:00')

跟随廖老师的脚步,么么哒!!


  • 1

Reply