Why is the date in datepicker angular showing the last day?

前端 未结 6 742
深忆病人
深忆病人 2021-01-12 13:13

I use datepicker c angular material. Here\'s the code:


 
6条回答
  •  渐次进展
    2021-01-12 13:39

    if you are not using moment or dont want to override complete date-datapter then you can override native-date-adapter

    @Injectable({        providedIn: 'root' }) 
    export class CustomDateAdapterService extends NativeDateAdapter {    
        public createDate(year: number, month: number, date: number): Date {
            const localDate = super.createDate(year, month, date);
            const offset = localDate.getTimezoneOffset() * 60000;
            return new Date(localDate.getTime() - offset); // utcDate
        } 
    }
    

    gist here

提交回复
热议问题