Discuss / Python / exercise(datetime)

exercise(datetime)

Topic source

叫我_小军

#1 Created at ... [Delete] [Delete and Lock User]

def to_timestamp(ut,utc): utc = re.match(r'^[\w]{3}([+-][\d]+):00$', utc).group(1) utc = int(utc) udt = datetime.strptime(ut, '%Y-%m-%d %H:%M:%S') udtz = udt.replace(tzinfo=timezone(timedelta(hours=utc))) uts = udtz.timestamp() return print(uts)

t1 = to_timestamp('2015-6-1 08:10:30', 'UTC+7:00') t2 = to_timestamp('2015-5-31 16:10:30', 'UTC-09:00')

--输出结果-- 1433121030.0 1433121030.0


  • 1

Reply