Java LocalDateTime Calculate dayDuration(LocalDateTime startDateTime, LocalDateTime endDateTime)

Here you can find the source of dayDuration(LocalDateTime startDateTime, LocalDateTime endDateTime)

Description

day Duration

License

Apache License

Declaration

public static long dayDuration(LocalDateTime startDateTime, LocalDateTime endDateTime) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.time.*;

import java.time.temporal.ChronoUnit;
import java.util.Date;

public class Main {
    public static long dayDuration(LocalDateTime startDateTime, LocalDateTime endDateTime) {
        return duration(startDateTime, endDateTime).toDays();
    }/*from  w  ww. java  2s .c  o m*/

    public static long dayDuration(LocalDate startDate, LocalDate endDate) {
        return ChronoUnit.DAYS.between(startDate, endDate);
    }

    public static long dayDuration(Date startDate, Date endDate) {
        long time1 = startDate.getTime();
        long time2 = endDate.getTime();
        long diff;

        if (time1 < time2) {
            diff = time2 - time1;
        } else {
            diff = time1 - time2;
        }

        return diff / (1000 * 60 * 60 * 24);
    }

    public static Duration duration(LocalDateTime startDateTime, LocalDateTime endDateTime) {
        return Duration.between(startDateTime, endDateTime);
    }
}

Related

  1. convertDatabaseDateToUSTime(LocalDateTime databaseDate)
  2. converterZoneDatetimeToLocalDateTime( final String date)
  3. currentTimeMillis(LocalDateTime ldt)
  4. DateTime2LocalDateTime(Date datetime)
  5. dateTimeToOleMinutes(LocalDateTime datetime)
  6. fastDateTimeWriteHours(LocalDateTime localDateTime)
  7. getShiftResult(ImmutableMap timexUnitMap, LocalDateTime reference, boolean future)
  8. getStartWeekOfMonth(@Nonnull final LocalDateTime aDT, @Nonnull final Locale aLocale)
  9. getTimePart(final LocalDateTime dateTime)