最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular: Format Moment to show as Date in html - Stack Overflow

programmeradmin3浏览0评论

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

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

Share Improve this question edited Nov 9, 2019 at 4:37 asked Nov 9, 2019 at 4:29 user12250118user12250118
Add a ment  | 

1 Answer 1

Reset to default 6

You need to use the date pipe as,

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

To remove leading zeros, do this

{{dateStart | date: 'M/d/yyyy'}} 
发布评论

评论列表(0)

  1. 暂无评论