Java Utililty Methods LocalDateTime to

List of utility methods to do LocalDateTime to

Description

The list of methods to do LocalDateTime to are organized into topic(s).

Method

DateconvertLocalDateTimeToDateInUTC(final LocalDateTime ldt)
convert Local Date Time To Date In UTC
final Instant instant = ldt.toInstant(ZoneOffset.UTC);
return Date.from(instant);
DateconvertToDate(LocalDateTime dateTime)
convert To Date
ZonedDateTime zdt = dateTime.atZone(ZoneId.systemDefault());
return Date.from(zdt.toInstant());
InstantfromLocalDateTime(LocalDateTime _ldt)
Get LocalDateTime as Instant for defined localZone
return _ldt.toInstant(localZoneOffset);
DategetDate(LocalDateTime time)
Creates a java.util.Date from the given java.time.LocalDateTime based on the UTC time zone.
Instant instant = time.toInstant(ZoneOffset.UTC);
return Date.from(instant);
StringgetDateTimeText(LocalDateTime dateTime)
Gets the complete date time text in the following format: 12 August 2015, 12:34 PM
return dateTime.format(DateTimeFormatter.ofPattern(FORMAT_FULL_DATE));
longgetDelayUntil(final LocalDateTime ldt)
get Delay Until
final LocalDateTime now = LocalDateTime.now();
long delayInMillis = Duration.between(now, ldt).getSeconds() * 1000;
if (delayInMillis <= 0) {
    delayInMillis = 0;
return delayInMillis;
longgetDifference(LocalDateTime sourceTime, LocalDateTime targetTime)
get Difference
return targetTime.until(sourceTime, ChronoUnit.MINUTES);
longgetDurationInMillis(LocalDateTime from, LocalDateTime to)
get Duration In Millis
return getInMillis(to) - getInMillis(from);
StringgetDurationString(LocalDateTime start, LocalDateTime end, ChronoUnit unit)
get Duration String
return unit.between(start, end) + " " + unit.name();
longgetHoursElapsed(LocalDateTime fromDate)
get Hours Elapsed
return fromDate.until(LocalDateTime.now(), ChronoUnit.HOURS);