Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Angular 2中格式化日期时间_Angular - Fatal编程技术网

在Angular 2中格式化日期时间

在Angular 2中格式化日期时间,angular,Angular,如何以Angular2显示日期时间 {{dte}} 它打印日期2014-10-10T11:42:28.000Z 而我需要它像这样打印: 2015年10月10日只需使用带有ur{{{dte}的管道过滤器即可 只需使用{{dte | date:'MM/dd/yyyy@h:mma'}} 它将为您提供所需的输出:)您可以将moment.js用作第三方 amDateFormat管道 import {DateFormatPipe} from 'angular2-moment'; @Component

如何以Angular2显示日期时间

{{dte}}

它打印日期
2014-10-10T11:42:28.000Z

而我需要它像这样打印:


2015年10月10日

只需使用带有ur{{{dte}的管道过滤器即可

只需使用{{dte | date:'MM/dd/yyyy@h:mma'}}


它将为您提供所需的输出:)

您可以将moment.js用作第三方

amDateFormat管道

import {DateFormatPipe} from 'angular2-moment';
    @Component({
      selector: 'app',
      pipes: [DateFormatPipe],
      template: `
        Last updated: <time>{{myDate | amDateFormat:'LL'}}</time>
      `
    })

Prints Last updated: January 24, 2016 
从“angular2矩”导入{DateFormatPipe};
@组成部分({
选择器:“应用程序”,
管道:[DateFormatPipe],
模板:`
上次更新:{{myDate | amDateFormat:'LL'}
`
})
上次更新日期:2016年1月24日
文档:

使用:

您可以选择预定义的格式(例如
shortDate
):

或指定自定义格式:

{{dte | date:'MM dd, yyyy'}}

此外,要使用RFC时间标准,只需编写以下格式
dd.MM.yy HH:MM

{{ yourDate | date:'dd.MM.yy HH:mm' }} 

输出将为:
15.11.2018 16:38

否,它不工作。它为管道“DatePipe”提供了errro“无效参数”2016-07-20T11:42:28.000Z它对我来说工作正常,我刚刚确认了你的情况…我得到的日期格式与你的相同,但在筛选后我得到了正确的结果完美解决方案,它可以更改为你想要的任何格式,就像我使用的:日期:'yyyy-MM-dd hh:MM'
{{dte | date:'MM dd, yyyy'}}
{{ yourDate | date:'dd.MM.yy HH:mm' }}