我正在尝试在 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