[英]Calendar on Angular 2 using PrimeNG date in milliseconds
I have time in milliseconds in calendar component of PrimeNG 我在PrimeNG的日历组件中有毫秒的时间
HTML 的HTML
<p-calendar [(ngModel)]="task.startDate"
[minDate]="minDateValue"
[maxDate]="maxDateValue"
readonlyInput="readonlyInput"
[showIcon]="true">
</p-calendar>
TypeScript 打字稿
"startDate":1490039621704,
But instead I am getting the following error 但是相反,我收到以下错误
EXCEPTION: Uncaught (in promise): TypeError: date.getMonth is not a function
TypeError: date.getMonth is not a function
Is there a way to tell the component to read the date in specific format, like in my case it is milliseconds 有没有办法告诉组件以特定格式读取日期,例如我的情况是毫秒
According to documentation here , date format in milliseconds should be @ - Unix timestamp (ms since 01/01/1970) so I added attribute dateFormat="@"
to the component, but doesn't seem to fix it. 根据此处的文档,以毫秒为单位的日期格式应该为@-Unix时间戳(自1970年1月1日开始 ,以毫秒为单位),因此我向组件添加了属性
dateFormat="@"
,但似乎并未对其进行修复。
Base on the error, it is expecting a Date Object . 基于该错误,它期望一个Date对象 。
Try: 尝试:
date = new Date(task.startDate);
The error may happen before server response with task.startDate
value. 该错误可能在具有
task.startDate
值的服务器响应之前发生。 If that is the case, initializing task.startDate
with 0 at the component level may fix the issue. 在这种情况下,在组件级别用0初始化
task.startDate
可能会解决此问题。
export class AppComponent {
task = { startDate: 0 };
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.