Angular 2显示当前格式化的日期 [英] Angular 2 show current formatted date
本文介绍了Angular 2显示当前格式化的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码来显示当前日期:
I have the following code to show the current date:
this.whatTime = Observable.interval(1000).map(x => new Date()).share();
在我的模板中:
{{whatTime | async}}
我的问题是日期太长而且没有按照我的意愿格式化。
My problem is that the date is too long and not formatted as I wish.
我想要展示的是:15/09 / 16 19:07:11
All I want to show is: 15/09/16 19:07:11
任何想法?
推荐答案
使用Angular的内置 DatePipe
:
Use Angular's built-in DatePipe
:
{{ whatTime | async | date:'d/M/yy hh:mm:ss' }}
这会转换 2016年9月15日星期四18:15:17 GMT + 0200(中欧夏令时)
进入您想要的模板: 15/9/16 06:15:17
。
This converts Thu Sep 15 2016 18:15:17 GMT+0200 (Central Europe Daylight Time)
into your desired template: 15/9/16 06:15:17
.
您可以阅读更多关于Angular的 DatePipe
及其格式这里你可以阅读更多关于Angular管道的信息此处。
You can read more about Angular's DatePipe
and its formats here and you can read more about Angular's pipes in general here.
这篇关于Angular 2显示当前格式化的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文