I am calling an API from where I am getting date /Date(1365004652303-0500)/
, I don\'t understand what format this is. How is this date format called? I was not
This is what I'm using to parse timestamps from a Xero API. It accounts for:
Code:
if (preg_match('#^(/Date\()([-]?[0-9]+)([0-9]{3})([+-][0-9]{4})?(\)/)$#', $data, $matches)) {
// Handle Xero API DateTime formats. Examples:
// "/Date(1436961673000)/" - unix timestamp with milliseconds
// "/Date(1436961673000+0100)/" - with an additional timezone correction
// "/Date(-1436961673000-0530)/" - before the epoch, 1924 here
//
// RE matches for "/Date(1436961673090+0100)/":
// [1] = (/Date\() "/Date("
// [2] = ([-]?[0-9]+) "1436961673" epoch seconds
// [3] = ([0-9]{3}) "090" milliseconds
// [4] = ([+-][0-9]{4})? "+0100" or "" optional timezone
// [5] = (\)/) ")"
$result = \DateTime::createFromFormat('U u', $matches[2] . ' ' . $matches[3] . '000')
->setTimezone(new \DateTimeZone($matches[4] ?: '+0000'));
}