应用程序正在从Web服务(不在我的控制下)中读取,该服务返回日期变量“0001-01-01T00:00:00”,这应该是指“午夜”。但是,当我要求角度格式化日期作为中等时间我得到“12:09:24 AM”。我不明白9分24秒来自何处。
Plunkr:
https://plnkr.co/edit/hdC4cFYkSdw2E8RzhFJP?p=preview
组件
@Component({
selector: 'my-app',
template: `
<div>
<h2>Object:</h2>
<pre>{{myThing | json}}</pre>
<h2>Message Time: {{myThing.messageTime}}</h2>
<h2>The message time formatted is {{myThing.messageTime | date:'mediumTime'}}</h2>
</div>
`,
})
打字稿
export class App {
name:string;
myThing: MyThing;
constructor() {
var json = '{ "messageTime" : "0001-01-01T00:00:00", "message" : "This is your message"}';
this.myThing = <MyThing>JSON.parse(json);
}
}
export class MyThing
{
messageTime: date;
message: string;
}