【问题标题】:How to show a date in a specific format [duplicate]如何以特定格式显示日期[重复]
【发布时间】:2018-03-14 23:58:39
【问题描述】:

我是角度和打字稿的新手。我们是一种日期格式,以 yyyy-mm 显示日期,但我必须在 UI 上显示它的方式是 2018 年 2 月。我使用了拆分功能 我建立 var dateformat = (2018-02).split('-')。 reverse ().join(' ') 这给了我 02 2018,但是我无法将 02 更改为 2 月 请指教

【问题讨论】:

标签: javascript angular date typescript


【解决方案1】:

Angular 有一个内置的日期管道:https://angular.io/api/common/DatePipe

有关管道的更多信息,请参阅https://angular.io/guide/pipes

在你的情况下:

import { Component } from '@angular/core';

@Component({
    selector: 'my-component',
    template: `Date {{ myDate | date:'LLL yyyy' }}`
})
export class MyComponent {
    myDate = new Date(2018, 2, 1);
}

【讨论】:

    猜你喜欢
    • 2018-04-15
    • 2019-05-05
    • 2015-08-06
    • 1970-01-01
    • 2017-06-07
    • 1970-01-01
    • 2017-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多