简体   繁体   中英

How to convert ISO8601 json to normal date format

I am getting follwing json from the backend

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.

What is the creationDate for a type? Date?

Thanks in advance!

Backend should send the date in some different format, like ISO8601 or timestamp. What you posted is not ISO format, but probably java representation of LocalDateTime . ISO date looks like 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.

For formatting purposes you can then use moment.js , or some other library.

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