python实现格林威治时间到北京时间的转化
# ===UTC2BJS def UTC2BJS(UTC): UTC_format = "%Y-%m-%dT%H:%M:%S.%fZ" BJS_format = "%Y-%m-%d %H:%M:%S" UTC = datetime.strptime(UTC,UTC_format) #格林威治时间+8小时变为北京时间 BJS = UTC + timedelta(hours=8) BJS = BJS.strftime(BJS_format) return BJS # ===BJS2UTC def BJS2UTC(BJS): UTC_format = "%Y-%m-%dT%H:%M:%S.%fZ" BJS_format = "%Y-%m-%d %H:%M:%S" BJS = datetime.strptime(BJS,BJS_format) #北京时间-8小时变为格林威治时间 UTC = BJS - timedelta(hours=8) UTC = UTC.strftime(UTC_format) return UTC