如何使用 Python 解析这样的时间 '/Date(-62135596800000)/'?
我搜索了 Internet,但无法找到解决方案。
链接:http://211.137.19.74:8089/Ajax/GetStationDetailList?cityName=%E6%B2%88%E9%98%B3
时间点:“/日期(-62135596800000)/” 时间应该是2016:12:31:01:00
最佳答案
/Date(N)/
通常是由 .NET 中内置的 WCF JSON 序列化程序序列化的日期格式。然后可以通过在 JavaScript 中调用 new Date(N)
来重建该值。
在 JavaScript 中运行它会显示为什么这个日期很可能是错误的:
new Date(-62135596800000)
// Date 0001-01-01T00:00:00.000Z
如您所见,您得到了 0001-01-01 00:00:00.00
。这也恰好是 .NET 中空 DateTime
对象的默认值:
default(DateTime).ToString("u") // 0001-01-01 00:00:00Z
new DateTime(0).ToString("u") // 0001-01-01 00:00:00Z
所以,很抱歉这么说,但那台服务器刚刚坏了。
综上所述,一旦获得有效日期,就可以使用 datetime.fromtimestamp
在 Python 中解析数字或 datetime.utcfromtimestamp
:
>>> from datetime import datetime
>>> datetime.fromtimestamp(1483120713887 // 1000)
datetime.datetime(2016, 12, 30, 18, 58, 33)
关于python - 如何用 Python 解析这样的时间 '\/Date(-62135596800000)\/',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41399572/