#!/usr/bin/env python
#author: linuxhub.cn
# coding=utf-8
import datetime
def local_to_utc(local_date_time):
local_time = datetime.datetime.strptime(local_date_time,'%Y-%m-%d %H:%M')
utc_time = local_time - datetime.timedelta(hours=8)
utc_date_time = utc_time.strftime("%Y-%m-%dT%H:%M:%SZ")
return utc_date_time
local_date_time="2020-04-02 15:46"
print "转换前: " + str(local_date_time)
print "转换后: " + str(local_to_utc(local_date_time))
# python demo.py
转换前: 2020-04-02 15:46
转换后: 2020-04-02T07:46:00Z
网友评论