简体   繁体   中英

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

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

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

How do I display to show, '3/8/2019'?

If converting in Typescript, we have to take existing class, and recreate new class with last two data types as date. Just curious if there is Displayformat Angular in HTML or Pipe function? Where its converted in 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

Convert string to date using moment.js

How to set today date and time as default in angular-moment-picker

You need to use the date pipe as,

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

To remove leading zeros, do this

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

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