![]() The between() method returns a Period consisting of the number of years, months, and days between two dates. Period.between() for Difference in Days, Months and Years We can even use the instances of ZonedDateTime to know the difference when both dates are in different time zones. Long diffInHours = (dateTime, dateTime2) Long diffInMinutes = (dateTime, dateTime2) ![]() Long diffInMilli = (dateTime, dateTime2) Long diffInSeconds = (dateTime, dateTime2) LocalDateTime dateTime2 = LocalDateTime.now() LocalDateTime dateTime = LocalDateTime.of(1988, 7, 4, 0, 0) But in that case, we will have to use LocalDateTime in place of LocalDate, because LocalDate does not have any time information associated with it. We can use ChronoUnit to know the difference in smaller time units e.g. Long diffInYears = (dateOfBirth, currentDate) Long diffInMonths = (dateOfBirth, currentDate) Long diffInDays = (dateOfBirth, currentDate) LocalDate dateOfBirth = LocalDate.of(1980, Month.JULY, 4) We can use its different types of instances to find the difference in specific time measures. The ChronoUnit instance represents a standard set of date periods units. ChronoUnit.between() for Difference in All Time Units Java 8 made the first attempt to upgrade this date/time API. Legacy Java classes have always been lacking enough support to express dates and time periods in an effective way. Duration.between() for Difference in Hours, Minutes and Seconds
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |