时间字符串看起来像[Datetime的OData版本2JSON详细格式,可以在旧的ASP.NET或WCF应用程序中看到:
“ / Date(
[“ +” |“-” ])/” =自1970年1月1日午夜以来的毫秒数 = utc偏移量
输出量#!/usr/bin/env python3import refrom datetime import datetime, timedelta, timezonetime_string = u"/Date(1409522400000+0200)/"epoch = datetime(1970, 1, 1, tzinfo=timezone.utc)ticks, offset = re.match(r'/Date((d+)([+-]d{4})?)/$', time_string).groups()utc_dt = epoch + timedelta(milliseconds=int(ticks))print(utc_dt)if offset: offset = int(offset) hours, minutes = divmod(abs(offset), 100) if offset < 0: hours, minutes = -hours, -minutes dt = utc_dt.astimezone(timezone(timedelta(hours=hours, minutes=minutes))) print(dt)
2014-08-31 22:00:00+00:002014-09-01 00:00:00+02:00
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)