如何获取“本周”的日期/时间范围?在 Java 中使用 Joda 日期/时间库?
假设您可以计算“今天”的日期/时间范围 按照 Jon Skeet 的建议:
LocalDate today = now.toLocalDate();
LocalDate tomorrow = today.plusDays(1);
DateTime startOfToday = today.toDateTimeAtStartOfDay(now.getZone());
DateTime startOfTomorrow = tomorrow.toDateTimeAtStartOfDay(now.getZone());
Then check if startOfToday <= time < startOfTomorrow for any particular time.
你会如何做类似的事情“这个 星期”。
因此,如果“今天”是 20:38 29/06/2011,“本周”将是
20:38 22/06/2011 - 20:38 29/06/2011
Assuming you can calculate the date/time range for "today" by following Jon Skeet's advice:
LocalDate today = now.toLocalDate();
LocalDate tomorrow = today.plusDays(1);
DateTime startOfToday = today.toDateTimeAtStartOfDay(now.getZone());
DateTime startOfTomorrow = tomorrow.toDateTimeAtStartOfDay(now.getZone());
Then check if startOfToday <= time < startOfTomorrow for any particular time.
How would you do something similar for "this week".
So, if "today" is 20:38 29/06/2011, "this week" would be
20:38 22/06/2011 - 20:38 29/06/2011
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(注:工作日以1为基数)
(Note: week days are 1-based)