简体   繁体   中英

Angular Material 2 DatePicker Date Format Using Moment

I am using Angular Material 2 date picker and want to format the date like - 'Sat 02-Mar-19'.

There is a guideline how to do that in Angular Material, as I am new to moment js and not familiar with it, so not able to get the expected format.

I tried to format the date by looking into the moment doc by changing the options provided by Angular Material but no luck.

What change I should do into the configuration provided by Angular material to get the date like - 'Sat 02-Mar-19'.

After spending a few hours on moment js document following material config work perfectly -

export const MY_FORMATS = {
  parse: {
    dateInput: 'ddd DD-MMM-YY',
  },
  display: {
    dateInput: 'ddd DD-MMM-YY'
  }
};

Hoping that this will save an hour for someone.

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