from datetime import datetime,timedelta ss = ' Mon, 01 Jul 2019 08:24:31 ' a = datetime.strptime(ss, " %a, %d %b %Y %H:%M:%S ")-timedelta(hours=8) a = str(a).replace('-','年',1).replace('-','月',1) print("a",a)
UTC时间比北京时间提早八个小时,因此使用timedelta方法减去八个小时就能够了spa
而replace方法它能够有三个参数,old,new,maxcode
max就是替换几回,默认所有blog