简体   繁体   English

将UTC日期转换为JavaScript中的日期/时间格式

[英]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 . 我正在使用仅提供UTC日期/时间的API(因为它是publishedDate I want to convert that field into a specific date format, for example, dmY or H:i . 我想将该字段转换为特定的日期格式,例如dmYH:i An example API field would be. 一个示例API字段将是。

{
    "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? 香草javascript中有什么方法可以将该值转换为我指定的人类可读日期格式?

I am using VueJS to render the API fields so I can attach a method to this specific field during the rendering phase. 我正在使用VueJS渲染API字段,因此我可以在渲染阶段将方法附加到该特定字段。 However, I am keen not use momentJS as I don't want to introduce a dependency for one JSON field. 但是,我不希望使用momentJS因为我不想为一个JSON字段引入依赖项。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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