Pregunta

I'm trying to build a rss bridge to obtain all gawker press articles in my rss reader (as their rss streams only show excerpts from these articles).

Examining a page with Firebug, I've found out there is a timestamp associated with each article, which is good.

However, when feeding an online timestamp converter with those, I find the returned date is not correct. As an example, this article Unified Remote Gets iOS App, Mac Server for Cross-Platform Control has as timestamp 1396017000991 which a javascript associates with 3/28/14 7:30am.

Could it be like in another PHP question MMDDYYhhmmss ? Well, no, as it would be month 13 day 96 year 01.

So, what is used format ? And how can I parse it to a meaningful UNIX timestamp ?

[EDIT 1] According to FMDiff, this timestamp is none of

  • UNIX Decimal
  • MAC Decimal
  • FM Dec Decimal (whatever it is)

[EDIT 2]] Initial answer appeared quite good, but my tests using PHP Repl revealed it was not so clear :

$epoch = 1396018800571;
echo date('r', $epoch);

Echoes "Fri, 29 Jan 46208 01:09:31 +0100" (not good)

Obviously, using $epoch/1000 work in that case, but when i try to inject this date in my timestamp, it results in wrong date.

¿Fue útil?

Solución

It looks like a Javascript timestamp, the number of milliseconds since the beginning of the epoch. Dividing by 1000 should give you the UNIX timestamp. See PHP code below.

function js_to_unix_timestamp($jsTimestamp){
  return $jsTimestamp/1000; 
}

$timestamp = 1396017000991; //Expect 3/28/14 7:30am

echo date('r', js_to_unix_timestamp($timestamp));
//Actual Fri, 28 Mar 2014 15:30:00 +0100
//Correct to within some UTC offset

$timestamp = 1396018800571; //Given in question
echo date('r', js_to_unix_timestamp($timestamp));
//Actual Fri, 28 Mar 2014 16:00:00 +0100 
//Correct?

$timestamp = 1396032315623; //Current time given by Date.now() in javascript
echo date('r', js_to_unix_timestamp($timestamp));
//Actual Fri, 28 Mar 2014 19:45:15 +0100
//Correct 
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top