我尝试将字符串转换为时刻并且检查是相同的。
protected showEvent(event: IEvent, hour: Moment): boolean {
let formatDate: Moment = moment(event.futureDate);
console.log('--> formatDate', formatDate);
console.log('--> hour', hour);
return formatDate.isSame(hour, "hour"); // return true is same
}
此控制台结果
--> formatDate: Moment {_isAMomentObject: true, _i: "07-24-2017 07:00:00.000", _isUTC: false, _pf: Object, _locale: Locale…}_d: Mon Jul 24 2017 07:00:00 GMT+0200 (CEST)_i: "07-24-2017 07:00:00.000"}
--> hour: Moment {_isAMomentObject: true, _isUTC: false, _pf: Object, _locale: Locale, _d: Tue Jul 25 2017 07:00:00 GMT+0200 (CEST)…}
如何转换日期以查看时间是否相同?
编辑:整个看起来像这样
protected showEvent(event: IEvent, hour: Moment): boolean {
return moment(event.futureDate).hour() == hour.hours()
}
答案 0 :(得分:0)
尝试单独比较小时值。
return formatDate.hours() == hour.hours()
如果您想比较整个日期,可以比较其他值,例如minutes()