我从某个API中获得了以下内容:
/Date(-27734400000+0000)/
它被称为什么格式?如何将其转换为时间戳?
发布于 2017-03-27 15:56:35
无论出于什么原因,C#似乎都会像这样序列化DateTime对象。通常它的格式是/Date(Seconds since 01/01/1970)/,但事实上它是负的(而且很大),这让我怀疑在某个地方有溢出。无论如何,做一些类似这样的事情:
<?php
$str = "/Date(-27734400000+0000)/";
$strTime = substr($str,6,-2);
$date = new \DateTime();
$date->setTimestamp(intval($strTime));
//You can also do some more sophisticated things to set the timezone based on the +xxxx part
print_r($date);这份打印(在http://sandbox.onlinephpfunctions.com/code/8e65641fa2aae0a3f49ce9c3f27457d7c6842b7b上)
DateTime Object (
[date] => 1091-02-17 16:00:00.000000
[timezone_type] => 3
[timezone] => US/Pacific
)这对我来说没有任何意义,除非你期望的是1091年的某个日期。我认为这很可能是一个API错误,您应该通知开发人员。
https://stackoverflow.com/questions/43040155
复制相似问题