How do you get the date/time range for "today" using the Joda date/time library in Java?
Translations
Englishالعربية
български
català
中文
čeština
dansk
Nederlands
eesti
suomi
français
Deutsch
Ελληνικά
עברית
हिंदी
magyar
Bahasa Indonesia
italiano
日本語
한국어
latviešu
lietuvių
norsk
polski
Português
română
русский
slovenčina
slovenski
español
svenska
ไทย
Türkçe
українська
Tiếng Việt
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.
This question and answers originated from www.stackoverflow.com
Question by Morris (6/29/2011 6:22:14 PM)
Answer |
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.
Answer by Jon Skeet
Find More Answers