0

I am working with an API that only provides a UTC date/time as it's publishedDate. I want to convert that field into a specific date format, for example, d-m-Y or H:i. An example API field would be.

{
    "title": "This is a title"
    "thumbnail": "/path/to/image.jpg"
    "slug": "slug-of-story"
    "publishedDate": "2019-07-02T13:38:15.215Z"
}

Is there a way in vanilla javascript I can convert this value into a human readable date format that I specify?

I am using VueJS to render the API fields so I can attach a method to this specific field during the rendering phase. However, I am keen not use momentJS as I don't want to introduce a dependency for one JSON field.

WebDevDanno
  • 1,062
  • 2
  • 20
  • 43
  • 2
    Possible duplicate of [How to format a JavaScript date](https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date) – GrafiCode Aug 06 '19 at 08:35

1 Answers1

0

var a=new Date();
console.log(a.getDate() +"\\"+ Number(1+a.getMonth()) +"\\"+ +Number(1900+a.getYear()))
ellipsis
  • 11,498
  • 2
  • 13
  • 33