我得到了错误。
无法读取未定义的属性“ toDate”。没有
apply(DF, 1, function(x) { temp = Events[Events$location %in% x["location"] x %>% mutate(overlap = pmax(pmin(temp$end, end) - pmax(temp$start, start) + 1,0)) })
我得到
时间戳(秒= 1545109200,纳秒= 0)
我引用了此Angular 6 firebase snapshot returns undefined
不过,将时间戳记转换为可读的日期字符串并不特定。 预期的输出将是2018年12月6日。
schedule-list.component.html
(Error in UseMethod("mutate_") :
no applicable method for 'mutate_' applied to an object of class "character")
schedule.model.ts
toDate() | Date
Pipe.ts
<div class="container ">
<div class="row">
<div *ngFor="let appoint of list" class="col-md-8 myCenter mt-2">
<!-- the bottom code should work if items within list exist. -->
<div class="card">
<div class="card-header">
Title: {{appoint.name}}
</div>
<div class="card-body">
<p>{{appoint.appointment_date.toDate() | date}}</p>
</div>
</div>
</div>
</div>
</div>
Schedule-list.component.ts
export class Schedule {
name:string;
appointment_date:string;
}
答案 0 :(得分:2)
您必须将时间戳乘以1000,我已经遇到了相同的问题;
尝试一下:
<p>{{ appoint.appointment_date.seconds * 1000 | date:'dd:MM:yyyy hh:mm:ss' }}</p>
答案 1 :(得分:0)
因为您有第二个时间戳,所以可以执行以下操作将其设置为日期:
ngOnInit() {
this.service.getAppointments().subscribe(actionArray =>{
this.list = actionArray.map(item =>{
return{
...item.payload.doc.data()
} as Schedule;
})
for(let i = 0; i < this.list.length; i++){
console.log(this.list[i].appointment_date); // to see if the data is undefined!
this.list[i].appointment_date = new Date(new Date(0).setUTCSeconds(this.list[i].appointment_date.seconds));
}
});
}
));