简体   繁体   English

Angular:格式化时刻以在 html 中显示为日期

[英]Angular: Format Moment to show as Date in html

I have a data type of type Moment in Angular, everytime it displays in Angular, it exhibits as我在 Angular 中有一个 Moment 类型的数据类型,每次它显示在 Angular 中时,它都显示为

<div>{{dateStart}}</div>

Fri Mar 08 2019 20:24:35 GMT-0800

How do I display to show, '3/8/2019'?如何显示“2019 年 3 月 8 日”?

If converting in Typescript, we have to take existing class, and recreate new class with last two data types as date.如果在 Typescript 中转换,我们必须采用现有的 class,并以最后两种数据类型作为日期重新创建新的 class。 Just curious if there is Displayformat Angular in HTML or Pipe function?只是好奇 HTML 或 Pipe ZC1C425268E68385D14AB5074C17A9 中是否有显示格式 Angular? Where its converted in HTML?它在 HTML 中转换在哪里?

export class Address {
    fullName: string;
    mailingAddress: string;
    phoneNumber: string;
    emailAddress: string;
    dateStart?: moment.Moment;
    dateEnd?: moment.Moment;

Resource questions:资源问题:

Angular: Format Moment to show as Date in html Angular:格式化时刻以在 html 中显示为日期

Convert string to date using moment.js 使用 moment.js 将字符串转换为日期

How to set today date and time as default in angular-moment-picker 如何在 angular-moment-picker 中将今天的日期和时间设置为默认值

You need to use the date pipe as,您需要使用date pipe作为,

{{dateStart | date: 'MM/dd/yyyy'}}

To remove leading zeros, do this要删除前导零,请执行此操作

{{dateStart | date: 'M/d/yyyy'}} 

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

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