#usr/bin/env python
#-*- coding:utf-8 -*-
__author__='teddy.xiong'
import re
from datetime import datetime,timezone,timedelta
def to_timestamp(dt_str,tz_str):
dt=datetime.strptime(dt_str,'%Y-%m-%d %H:%M:%S')
H=re.match(r'^([a-zA-Z]{3})(\+|\-)(0[0-9]|[0-9]|1[0-9]|2[0-4])\:(\d{2})$',tz_str)
hour=int(H.group(3))
if H.group(2)=='+':
date_time=dt-timedelta(hours=hour)
time_stamp=date_time.timestamp()
elif H.group(2)=='-':
date_time=dt+timedelta(hours=hour)
return time_stamp
t1 = to_timestamp('2015-6-1 08:10:30', 'UTC+7:00')
t2 = to_timestamp('2015-5-31 16:10:30', 'UTC-09:00')
print(t1)
print(t2)
Sign in to make a reply
少侠果然好身手啊
#usr/bin/env python
#-*- coding:utf-8 -*-
__author__='teddy.xiong'
import re
from datetime import datetime,timezone,timedelta
def to_timestamp(dt_str,tz_str):
dt=datetime.strptime(dt_str,'%Y-%m-%d %H:%M:%S')
H=re.match(r'^([a-zA-Z]{3})(\+|\-)(0[0-9]|[0-9]|1[0-9]|2[0-4])\:(\d{2})$',tz_str)
hour=int(H.group(3))
if H.group(2)=='+':
date_time=dt-timedelta(hours=hour)
time_stamp=date_time.timestamp()
elif H.group(2)=='-':
date_time=dt+timedelta(hours=hour)
time_stamp=date_time.timestamp()
return time_stamp
t1 = to_timestamp('2015-6-1 08:10:30', 'UTC+7:00')
t2 = to_timestamp('2015-5-31 16:10:30', 'UTC-09:00')
print(t1)
print(t2)