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:
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'}}
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;
}
}