Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SeriousJelly's avatar

Date Conversion

I am currently importing external data from a third party API using Scheduler. Everything works great, but the third party API provides dates in the following format:

"Date": "\/Date(1320224444000+0000)\/", 

What format is this?

How would I convert this to the standard MYSQL date/time using Laravel 5?

0 likes
5 replies
mstnorris's avatar

Use Carbon to parse it.

Carbon::parse('1320224444000+0000');

As for the format, I'm assuming some form of unix timestamp as 1320224444000 milliseconds in years is almost 42 years (41.86 to be exact). From the epoch (January 1st 1970), this would be around the end of 2011/ beginning of 2012.

See this SO question.

Running the 13 digit (unix time) through this online parser](http://www.onlineconversion.com/unix_time.htm) produces Wed, 02 Nov 2011 09:00:44 GMT making the above guess of late 2011 correct ;)

bobbybouwmann's avatar

@mstnorris This doesn't work Carbon::parse('1320224444000+0000'), it will throw an exception

DateTime::__construct(): Failed to parse time string (1320224444000+0000) at position 11 (0): Unexpected character

@SeriousJelly If you want to parse it, you can do something like this

// I know it's not the best way, but you get the correct result ;)

$value = "\/Date(1320224444000+0000)\/";

// We only want the this part of the string 132022444
// So we get the start position + 1
$timestamp = substr($value, strpos($value, '(') + 1, 11);

dd(Carbon::parse($timestamp));

This will return

Carbon {#114 ▼
  +"date": "2011-11-02 09:00:44.000000"
  +"timezone_type": 3
  +"timezone": "UTC"
}
SeriousJelly's avatar

@bobbybouwmann Nearly there! I get the following error:

DateTime::__construct(): Failed to parse time string (14486526000) at position 8 (0): Unexpected character

The $timestamp var is giving me: 14486526000

It seems Carbon is having issues parsing it?

Thanks :)

bobbybouwmann's avatar
Level 88

Oow sorry I forgot to update the answer, use this instead

Carbon::createFromTimestamp($timestamp);
2 likes

Please or to participate in this conversation.