我使用的是primeng日历但我无法从数据库设置日期。 这是我在服务器上的约会日期: 2018-04-17T16:41:47.683
当我尝试将格式更改为" YYYY.MM.DD HH.MM"有一刻,我在控制台上收到了这个错误: Uncaught(承诺):位置2的意外文字 当我将我的日期时间转换为字符串时,我得到相同的错误,我不知道该怎么做。请帮助
这是我的代码:
Component.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。
Component.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();
}
}
ContentTranslate:
export class ContentTranslate {
public StartDate: Date;
public FinishDate: Date;
public CreateDate: Date;
}