简体   繁体   中英

Convert UTC date into date/time format in javascript

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, dmY 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.

 var a=new Date(); console.log(a.getDate() +"\\\\"+ Number(1+a.getMonth()) +"\\\\"+ +Number(1900+a.getYear())) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM