问题描述
假设这是您如何获得的当前时间: DateTime now = new DateTime();
如何计算变量的值 dateTimeAtStartOfToday
和 dateTimeAtEndOfToday
?
我想要做的是生成一些SQL来查找所有事务发生在 startOfToday
和 endOfToday
之间。
我会使用:
LocalDate today = now.toLocalDate();
LocalDate tomorrow = today.plusDays(1);
DateTime startOfToday = today.toDateTimeAtStartOfDay(now.getZone());
DateTime startOfTomorrow = tomorrow.toDateTimeAtStartOfDay(now.getZone());
然后检查 startOfToday< = time< startOfTomorrow
在任何特定的时间。
当然,它部分取决于数据库中存储的内容以及您感兴趣的时区in。
Assuming this is how you get the current time in Joda time:
DateTime now = new DateTime();
How do you calculate values for the variables dateTimeAtStartOfToday
and dateTimeAtEndOfToday
?
What I'm trying to do is generate some SQL to do a lookup of all transactions that have occurred between the startOfToday
and endOfToday
.
I would use:
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.
Of course, it partly depends on exactly what's stored in the database - and what time zone you're interested in.
这篇关于如何获取“今天”的日期/时间范围在Java中使用Joda日期/时间库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!