Angular2 date pipe does not work in IE 11 and edge 13/14

前端 未结 8 1310
闹比i
闹比i 2020-12-05 09:50

I\'m using Angular 2.0 final, and I have an incorrect format of dates when I add hours and minutes in the format string:

In the template of the component, I have:

相关标签:
8条回答
  • 2020-12-05 10:08

    The below solution works fine in for IE11 and chrome. No need to create custom pipes.

     {{dto.createdTimeLocal | date:'dd MMM yyyy'}} {{dto.createdTimeLocal | date:'shortTime'}}
    
    0 讨论(0)
  • 2020-12-05 10:16

    Regarding the answer from @mark-hughes above, from the moment API documentation:

    date_expression | date[:format]

    expression is a date object or a number (milliseconds since UTC epoch) or an ISO string

    Reference

    So the value should be any type, and you can use moment().isValid() to check the value type

    @Pipe({name: 'datex'})
    export class DatexPipe implements PipeTransform {
        transform(value: any, format: string = ""): string {
           return moment(value).isValid()? moment(value).format(format) : value; 
        }
    }
    
    0 讨论(0)
提交回复
热议问题