Compare YouTube and Facebook dates

1

Through the YT API, I get the date of the video in this format (UTC):

publishedAt: "2015-09-17T00:01:56.000Z"

And on Facebook, inspecting the source code I see that they use:

<abbr title="Quinta, 17 de setembro de 2015 às 06:59" data-utime="1442465986" data-shorten="1" class="timestamp livetimestamp">5 h</abbr>

According to this question :

  

utime is UNIX_TIMESTAMP from a datetime (UTC) let's say 1402355007 for the UTC datetime of 2014-06-10 00:03:27

I want to compare exactly those two posts (YT and FB), so if you do the following for Facebook date:

var ms = 1442465986 * 1000;
dt = new Date(ms);
console.log(dt)

I get:

Thu Sep 17 2015 06:59:46 GMT+0200 (CEST)

In theory, almost seven hours after YouTube. The CEST is Central European Daylight Time. My doubts are

asked by anonymous 17.09.2015 / 13:11

1 answer

4

As far as I know JS automatically converts. I made some tests here in the Chrome console, follow the code:

var utime  = 1442465986 * 1000,
    ytData = "2015-09-17T00:01:56.000Z";

var d1  = new Date(utime),
    d2  = new Date(ytData),
    dif = parseInt(dayToHours(dateDifference(d1,d2)));

console.log("A diferença entre as datas é de : " + dif + " horas");

function dateDifference(d1, d2) {
  return d1 > d2 ? (d1 - d2) / 86400000 : (d1 - d2) / 86400000;
}

function dayToHours(day) {
  return day * 24;
}
    
17.09.2015 / 14:39