我的解决方案如下
//our root app component
import {Component, NgModule, VERSION} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
@Component({
selector: 'my-app',
template: `
<div>
<h2>Hello {{name}}</h2><br>
<h5>{{test | date: 'dd/MM/yyyy'}}</h5>
</div>
`,
})
export class App {
name:string;
test : Date = new Date('2017-04-30T23:59:59');
constructor() {
this.name = `Angular! v${VERSION.full}`;
console.log(this.test)
}
}
现场演示
更新 :
getExcatDate(string){
let year=new Date(this.name).getYear();
let month=new Date(this.name).getMonth();
let date=new Date(this.name).getDate();
let local= (date.toString().length===1 ? '0' +date : date) + '/' +
(month.toString().length===1 ? '0' +month : month)
+ '/' + year.toString().substring(1);
console.log(local)
return local;
}
使用上述方法获取确切的日期,因为 Pankaj 说日期管道不适用于您的情况。演示已更新