From aee7abe16cad2fe2619781019a28e1aa1b63cd00 Mon Sep 17 00:00:00 2001 From: JuniorTour Date: Sun, 26 Nov 2017 11:05:00 +0800 Subject: [PATCH] feat(module:datepicker): support string and number type as value (#593) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit change NzDatePipe to support display string type in valid ISO 8601 format (eg: '2013-02-08 09:30:26.123') and number type (eg: timestamp-'123456789') . 修改了NzDatePipe从而支持显示输入的ISO 8601时间格式的字符串类型(如: “2013-02-08 09:30:26.123”)和数字类型(如:时间戳-“123456789”)。 --- src/components/util/nz-date.pipe.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/util/nz-date.pipe.ts b/src/components/util/nz-date.pipe.ts index 4b10372d6e3..de6c0b2d835 100644 --- a/src/components/util/nz-date.pipe.ts +++ b/src/components/util/nz-date.pipe.ts @@ -3,11 +3,11 @@ import * as moment from 'moment'; @Pipe({ name: 'nzDate' }) export class NzDatePipe implements PipeTransform { - transform(value: Date, formatString: string): string { - if (value) { - return moment(+value).format(formatString); + transform(value: Date | number | string, formatString: string): string { + if (moment(value).isValid()) { + return moment(value).format(formatString); } else { - return ''; + return 'Invalid Date'; } } }