JSON Date对象PHP日期对象、日期、JSON、Date

2023-09-03 07:27:07 作者:初三励志当学霸!

我打电话web服务这回我回JSON对象。 JSON对象EN codeS的日期。我试图找到一种方法,该日期转换为MDY格式的PHP。 JSON对象是。{出生日期:\ /日期(387518400000-0400)\ /}这个日期是1982年2月15日

I am calling a webservice which return me back a json object. The json object encodes the date. I am trying to find a way to convert that date to m-d-Y format in php. Json object is {"DateOfBirth":"\/Date(387518400000-0400)\/"} this date is 02-15-1982.

这我打电话的web服务是.NET,它日至JSON对象转换。不知道这是否会有所帮助。

The webservice which I am calling is in .NET, and it converts the date to the JSON object. Not sure if this would help.

在此先感谢

谢谢, Tanmay

Thanks, Tanmay

推荐答案

如果有你说的1982年2月15日,但确实意味着1982年4月12日,那么我有一个解决方案的机会。如果没有,那么有一个在约60天的时间间隙,其可占多一点数学

If there's a chance you said 02-15-1982 but really meant 04-12-1982, then I have a solution. If not, then there's a gap in the time of about 60 days, which can be accounted for with a bit more math.

下面是我的解决方案现在:

Here's my solution for now:

date_default_timezone_set(  'America/Denver' );

$json = json_decode( '{"DateOfBirth":"\/Date(387518400000-0400)\/"}' );
$date_string = $json -> DateOfBirth;

preg_match( '/([\d]{9})/', $date_string, $matches ); // gets just the first 9 digits in that string

echo date( 'm-d-Y', $matches[0] );

这将返回: 1982年4月12日