0

I'm using the YouTube Data API for loading videos, and the video upload date is returning in IOS-8601 format:

2015-04-07T03:00:03.000Z

how can convert in it into

dd/mm/yyyy

or display it into something like:

yesterday or 4days ago;

2week ago;

1month ago;

1year ago;

Community
  • 1
  • 1
Huy4NG
  • 29
  • 1
  • 9

2 Answers2

0
var date = new Date("2015-04-07T03:00:03.000Z");

this should do the trick. What you have is basically a JSON enconded string representation of a date. It includes the date offset as well and it will keep it once you translate it back into a date object,

Andrei Dragotoniu
  • 6,155
  • 3
  • 18
  • 32
0

If your upload date was stored in variable date, you would do something like:

var date = new Date("2015-04-07T03:00:03.000Z");
var myDate = date.getDate() + "/" + (date.getMonth() + 1) + "/" + date.getFullYear();

getMonth() returns integer from 0 to 11 hence +1

Please refer to Javascript timestamp to relative time (eg 2 seconds ago, one week ago etc), best methods? for "ago" format.

Community
  • 1
  • 1
Stack
  • 348
  • 3
  • 17