简体   繁体   English

如何将ISO8601 json转换为正常日期格式

[英]How to convert ISO8601 json to normal date format

I am getting follwing json from the backend 我从后端获取json

creationDate:
 chronology: {id: "ISO", calendarType: "iso8601"}
 dayOfMonth: 4
 dayOfWeek: "TUESDAY"
 dayOfYear: 185
 hour: 4
 minute: 1
 month: "JULY"
 monthValue: 7
 nano: 351000000
 offset: {totalSeconds: 0, id: "Z", rules: {…}}
 second: 31
year: 2609
Uzone: {id: "UTC", rules: {…}}

I want to have YYYY-MM-DD HH:mm at the end. 我想在结尾处加上YYYY-MM-DD HH:mm。

What is the creationDate for a type? 类型的creationDate是什么? Date? 日期?

Thanks in advance! 提前致谢!

Backend should send the date in some different format, like ISO8601 or timestamp. 后端应该以其他不同的格式发送日期,例如ISO8601或时间戳。 What you posted is not ISO format, but probably java representation of LocalDateTime . 您发布的不是ISO格式,但可能是LocalDateTime java表示形式。 ISO date looks like 2018-01-20T12:00:00.000+01:00 . ISO日期看起来像2018-01-20T12:00:00.000+01:00

On the frontend side, you can then just create new Date('2018-01-20T12:00:00.000+01:00') as javascript supports creating dates from ISO string. 在前端,您可以仅创建new Date('2018-01-20T12:00:00.000+01:00')因为javascript支持根据ISO字符串创建日期。

For formatting purposes you can then use moment.js , or some other library. 为了格式化,您可以使用moment.js或其他一些库。

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

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