0

I found reddit created and created_utc kinda weird to me. Can someone explain to me what am i missing here? When i'm subtracting comment creation date with new Date() i'm getting time from 2 weeks ago instead of date from 3 hours ago (for utc+2 timezone at 2 pm).

CodePen for "playground"

fetch(`https://www.reddit.com/r/hearthstone/comments/6kkoyi.json`)
  .then(res => res.json())
  .then(res=>{
  const comments = res[1].data.children.map(obj => obj.data);
  let date = comments[0].created
  console.log("Should show: Saturday, 1 July 2017 11:13:39 or ~3 hours",
              "\nUnix: "+ date, 
              "\nDistance from now: "+ dateFns.distanceInWordsToNow(date),
              "\nFormatted: " + dateFns.format(date),
              "\nDate from now: "+ dateFns.format(new Date() - date))
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/date-fns/1.28.5/date_fns.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/2.0.3/fetch.js"></script>

0

1 Answer 1

2

The timestamp is in seconds

So:

new Date(1498878149*1000);

Gives me:

2017-07-01T03:02:29.000Z
Sign up to request clarification or add additional context in comments.

1 Comment

Ahh indeed, forgot about that multiplication by 1000.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.