List of utility methods to do LocalDateTime to
Date | convertLocalDateTimeToDateInUTC(final LocalDateTime ldt) convert Local Date Time To Date In UTC final Instant instant = ldt.toInstant(ZoneOffset.UTC); return Date.from(instant); |
Date | convertToDate(LocalDateTime dateTime) convert To Date ZonedDateTime zdt = dateTime.atZone(ZoneId.systemDefault());
return Date.from(zdt.toInstant());
|
Instant | fromLocalDateTime(LocalDateTime _ldt) Get LocalDateTime as Instant for defined localZone return _ldt.toInstant(localZoneOffset);
|
Date | getDate(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);
|
String | getDateTimeText(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));
|
long | getDelayUntil(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; |
long | getDifference(LocalDateTime sourceTime, LocalDateTime targetTime) get Difference return targetTime.until(sourceTime, ChronoUnit.MINUTES);
|
long | getDurationInMillis(LocalDateTime from, LocalDateTime to) get Duration In Millis return getInMillis(to) - getInMillis(from);
|
String | getDurationString(LocalDateTime start, LocalDateTime end, ChronoUnit unit) get Duration String return unit.between(start, end) + " " + unit.name(); |
long | getHoursElapsed(LocalDateTime fromDate) get Hours Elapsed return fromDate.until(LocalDateTime.now(), ChronoUnit.HOURS);
|