I am looking for an equivalent Joda Time method in Java 8 comparing org.joda.time.DateTime instances (with the specified time zone), ignoring the seconds and milliseconds from the comparisons as follows.
DateTimeFormatter formatter = DateTimeFormat.forPattern("dd-MMM-yyyy hh:mm:ss:SSS a Z").withZone(DateTimeZone.forID("Asia/Kolkata")); DateTime first = formatter.parseDateTime("16-Feb-2012 12:03:45:999 AM +05:30"); DateTime second = formatter.parseDateTime("16-Feb-2012 12:03:55:999 AM +05:30"); DateTimeComparator comparator = DateTimeComparator.getInstance(DateTimeFieldType.minuteOfHour()); int compare = comparator.compare(first, second); System.out.println("compare : " + compare);
The comparison returns 0 , which means that both objects are considered equal after ignoring the seconds and millisecond moments from the comparison.
Fields whose value is less than the lower limit specified in DateTimeFieldType are ignored here.
What is the equivalent way to do the same using the Java Time API in Java 8?
Honestly, I was not able to achieve the same in Java 8 with my attempts.
source share