Java实例计算即时之间的持续时间
public class Student {
String firstName;
String secondName;
Instant lastClassAttendedOn;
}
嗨,我一直遇到一个学生名单的问题,我想找出上周至少参加过一堂课的所有学生。到上周,我的意思是从上一周的星期一到上一周星期五,因为学校在星期六和周日有一个假期。例如,我可能会在星期三的任何一天检查列表,所以我应该让所有上一周至少上课的学生
public class Student {
String firstName;
String secondName;
Instant lastClassAttendedOn;
}
Hi, I have been stuck on a problem where I have the list of students and I want to find out all the students who have attended at least one class in the previous week. By previous week, I mean from the previous week Monday to the previous week Friday as the school has a holiday on Saturday and Sunday. I might be checking the list any day of the week for example On Wednesday so I should get all the students who have taken at least a class in previous week
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于我们仅处理几天,因此使用
localdate
就足够了。从当前/今天的日期开始找出上周的起点和结束日期。然后循环浏览列表,并从开始日期开始滤除结果。在这里,
noofays
如果accesseddate
在较早的几周内,则可能具有负值。因此,请检查> = 0。我们要限制到上周的星期五。因此应该为< = 4。As we are dealing with only days, it's sufficient to use
LocalDate
. Find out the start and end dates of the previous week from the current/ today's date. Then loop through the list and filter out the results from the start date.Here,
noOfDays
may have negative values if theaccessedDate
lies in older weeks. So, check for >= 0. And we want to restrict till previous week's Friday. So it should be <= 4.