我正在使用primeng 日历,但我无法从数据库中设置日期。这是我来自服务器的日期:2018-04-17T16:41:47.683
当我尝试立即将格式更改为“YYYY.MM.DD HH.MM”时,我在控制台上收到此错误:Uncaught (in promise): Unexpected literal at position 2 当我将日期时间转换为字符串时,我得到同样的错误我不知道该怎么办。请帮忙
这是我的代码:
组件.html
<p-calendar id="StartDate" inputStyleClass="form-control" [showIcon]="true" showTime="true" hourFormat="24" [locale]="tr"
name="StartDate" [(ngModel)]="datex"></p-calendar>
<!-- <p-calendar id="StartDate" inputStyleClass="form-control" [showIcon]="true" showTime="true" hourFormat="24" [locale]="tr"
name="StartDate" [(ngModel)]="contentTranslate.StartDate"></p-calendar> -->
ps:我用ngmodel尝试了两种方式。
组件.ts
ngOnInit() {
this.getLanguageDetail(this.contentId, this.langId); }
getLanguageDetail(contentId: number, langId: number): any {
this.contentService
.getTranslateDetail(contentId, langId)
.subscribe(x => this.detailResultFunc(x));
}
detailResultFunc(x: any): any {
if (x) {
this.contentTranslate = x;
const tmpDate: string = moment(this.contentTranslate.StartDate).format('YYYY.MM.DD HH:MM');
this.datex = tmpDate; new Date(tmpDate).toLocaleDateString(); //.toLocaleDateString().trim();
} else {
this.contentTranslate = new ContentTranslate();
}
}
内容翻译:
export class ContentTranslate {
public StartDate: Date;
public FinishDate: Date;
public CreateDate: Date;
}