gpt4 book ai didi

javascript - 使用 Angular javascript的json日期格式

转载 作者:行者123 更新时间:2023-11-30 09:17:51 28 4
gpt4 key购买 nike

我正在尝试在 html 表中显示 json 数据。当我运行我的文件时,日期在我的表中显示为“2018-11-21T00:00:00.000+0000”。但我只需要显示'2018-11-21'。我该怎么做?你能帮我把它分开吗?

import { Certificate } from './certificate';

export const CERTIFICATES: Certificate[] = [
{ date: '2018-11-21T00:00:00.000+0000', ident: 'Fe', moy_certified: 0.297 },
{ date: '2018-11-22T00:00:00.000+0000', ident: 'Cu', moy_certified: 0.04 },
{ date: '2018-11-23T00:00:00.000+0000', ident: 'Mn', moy_certified: 0.0374 },
{ date: '2018-11-24T00:00:00.000+0000', ident: 'V', moy_certified: 0.019 },
{ date: '2018-11-25T00:00:00.000+0000', ident: 'Mn', moy_certified: 0.037 }
];
<ul class="cert-result">
<li *ngFor="let certificate of certificates">
<table>
<tr>
<th>Date</th>
<th>Element</th>
<th>Composition</th>
</tr>
<tr>
<td>{{certificate.date}}</td>
<td>{{certificate.ident}}</td>
<td>{{certificate.moy_certifiee}}</td>
</tr>
</table>
</li>
</ul>

最佳答案

您可以使用 Pipes (|):

Introducing Angular pipes, a way to write display-value transformations that you can declare in your HTML.

A pipe takes in data as input and transforms it to a desired output.

改变

<td>{{certificate.date}}</td>

<td>{{certificate.date | date:'yyyy-MM-dd'}}</td>

关于javascript - 使用 Angular javascript的json日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53809697/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com