I have first time as string '12:00:00' and another '19:00:00'. How to check time portion of the day is within these time values?
The idea is quite simple, just use Calendar class to roll the month back and forward to create a “date range”, and use the Date. before() and Date. after() to check if the Date is within the range.
Joda-Time is an API created by joda.org which offers better classes and having efficient methods to handle date and time than classes from java. util package like Calendar, Gregorian Calendar, Date, etc. This API is included in Java 8.0 with the java.
So the short answer to your question is: YES (deprecated).
Adjusting Time ZoneUse the DateTimeZone class in Joda-Time to adjust to a desired time zone. Joda-Time uses immutable objects. So rather than change the time zone ("mutate"), we instantiate a new DateTime object based on the old but with the desired difference (some other time zone). Use proper time zone names.
Using Joda Time you could do something like this:
DateTime start = new DateTime(2010, 5, 25, 12, 0, 0, 0);
DateTime end = new DateTime(2010, 5, 25, 21, 0, 0, 0);
Interval interval = new Interval(start, end);
DateTime test = new DateTime(2010, 5, 25, 16, 0, 0, 0);
System.out.println(interval.contains(test));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With