【发布时间】:2020-08-25 22:28:48
【问题描述】:
我正在尝试在 RealmJS 中查询生日的日期字段。
我想找出所有今天过生日的人。
问题是我不能忽略年份。有没有办法做到这一点?
我的代码:
const today = new Date();
const morning = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 0,0,0,0);
const evening = new Date(today.getFullYear(), today.getMonth(), today.getDate()+1, 0,0,0,0);
const studentBirthdaysToday = realm.objects('Student').filtered('birthday >= $0 && birthday < $1', morning, evening);
即使今天有学生过生日,它也不会显示,因为它正在寻找 2020 年。
如何忽略年份?
这是 student.birthday 在数据库中的格式,它是一个领域日期:
2000-08-25T10:00:00.000Z
【问题讨论】: