简体   繁体   English

如何在 Angular 中处理 LocaleDateTime 后端响应

[英]How to handle LocaleDateTime backend response in Angular

I have a table row as我有一个表格行

<ng-container cdkColumnDef="date">
          <mat-header-cell *cdkHeaderCellDef fxFlex="10%">Date</mat-header-cell>
          <mat-cell *cdkCellDef="let payroll"
                    fxFlex="10%"> {{payroll.creationDateTime}}</mat-cell>
</ng-container>

And here i want to show the date in logical format but the response coming from backend is :在这里我想以逻辑格式显示日期,但来自后端的响应是:

{
"id": 5,
"employeeId": 42198,
"budgetGroupId": 15541,
"creationDateTime": {
"year": 2018,
"month": "MARCH",
"monthValue": 3,
"dayOfMonth": 1,
"dayOfWeek": "THURSDAY",
"dayOfYear": 60,
"hour": 19,
"minute": 24,
"second": 3,
"nano": 190000000,
"chronology": {
"id": "ISO",
"calendarType": "iso8601"
}
}
}

How can i take that creationDateTime from there in a good format without taking all its inner values one by one and concat?我怎样才能以一种好的格式从那里获取 creationDateTime 而不用一个一个地获取它的所有内部值并连接?

Just use overfload of Date object.只需使用Date对象的过载。 The overload can be seen at mdn docs :可以在mdn docs 中看到重载:

new Date(year, monthIndex [, day [, hours [, minutes [, seconds [, milliseconds]]]]]);新日期(年,月索引[,日[,小时[,分钟[,秒[,毫秒]]]]]);

 let dateObject = { "id": 5, "employeeId": 42198, "budgetGroupId": 15541, "creationDateTime": { "year": 2018, "month": "MARCH", "monthValue": 3, "dayOfMonth": 1, "dayOfWeek": "THURSDAY", "dayOfYear": 60, "hour": 19, "minute": 24, "second": 3, "nano": 190000000, "chronology": { "id": "ISO", "calendarType": "iso8601" } } }; var date = new Date(dateObject.creationDateTime.year, dateObject.creationDateTime.monthValue - 1, dateObject.creationDateTime.dayOfMonth, dateObject.creationDateTime.hour, dateObject.creationDateTime.minute, dateObject.creationDateTime.second); console.log(date);

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

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