Compare Youtube and Facebook dates

Asked

Viewed 54 times

2

Through the YT API, I get the video date 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 the Facebook date:

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

Obtenho:

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

In theory, almost seven hours after Youtube. CEST is the summer time of Central Europe. My doubts are

1 answer

5


As far as I know JS automatically does the conversion. I did some testing here on 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;
}

  • Only that return d1 > d2 that has to be adjusted.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.