import time
import pytz
import datetime
date_=datetime.datetime(2018,6,19,20,55,00)
timestamp2=time.mktime(date_.timetuple())
print(timestamp2)
ltime=time.localtime(1529112900)
timeStr=time.strftime("%Y-%m-%d %H:%M:%S", ltime)
print(timeStr)
def utc_to_local(utc_time_str, utc_format='%Y-%m-%dT%H:%M:%SZ'):
local_tz = pytz.timezone('Asia/Chongqing')
local_format = "%Y-%m-%d %H:%M:%S"
utc_dt = datetime.datetime.strptime(utc_time_str, utc_format)
local_dt = utc_dt.replace(tzinfo=pytz.utc).astimezone(local_tz)
return int(time.mktime(local_dt.timetuple()))
def local_to_utc(local_ts, utc_format='%Y-%m-%dT%H:%MZ'):
local_tz = pytz.timezone('Asia/Chongqing')
local_format = "%Y-%m-%d %H:%M:%S"
time_str = time.strftime(local_format, time.localtime(local_ts))
dt = datetime.datetime.strptime(time_str, local_format)
local_dt = local_tz.localize(dt, is_dst=None)
utc_dt = local_dt.astimezone(pytz.utc)
return utc_dt.strftime(utc_format)
print(utc_to_local('2018-07-13T16:00:00Z', utc_format='%Y-%m-%dT%H:%M:%SZ'))
print(local_to_utc(1531411200, utc_format='%Y-%m-%dT%H:%MZ'))
'''
1529412900.0
2018-06-16 09:35:00
1531497600
2018-07-12T16:00Z
'''