List of utility methods to do LocalDateTime Calculate
boolean | shouldSend(Optional should Send if (emailSentOpt.isPresent()) { long lastEmailSent = emailSentOpt.get().atZone(ZoneId.systemDefault()).toInstant().getEpochSecond(); long now = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().getEpochSecond(); return timeToWait < Math.abs(lastEmailSent - now); return true; |
void | sleepUntil(LocalDateTime next) sleep Until while (true) { try { LocalDateTime now = LocalDateTime.now(); long intervalInMillis = now.until(next, ChronoUnit.MILLIS); if (intervalInMillis > 0) { Thread.sleep(intervalInMillis); return; ... |
Calendar | toCalendar(final LocalDateTime localDateTime) Converts local date time to Calendar. return GregorianCalendar.from(ZonedDateTime.of(localDateTime, ZoneId.systemDefault()));
|
OffsetDateTime | toOffsetDateTime(Date localDateTime, TimeZone clientTimeZone) Converts the given local server time to the given TimeZone . Objects.requireNonNull(localDateTime, "Local time is required"); Objects.requireNonNull(clientTimeZone, "Time zone is required"); return ZonedDateTime.ofInstant(Instant.ofEpochMilli(localDateTime.getTime()), ZoneId.systemDefault()) .withZoneSameInstant(clientTimeZone.toZoneId()).toOffsetDateTime(); |
LocalDateTime | WizzAirDatetimeCorrection(LocalDateTime aLocalDateTime) Wizz Air Datetime Correction ZonedDateTime lZDT = aLocalDateTime.atZone(ZoneId.of("Europe/Budapest")); ZoneOffset lZO = lZDT.getOffset(); String lZId = lZO.getId(); Pattern reg = Pattern.compile("(\\+|-)(\\d{2})\\:(\\d{2})"); Matcher m = reg.matcher(lZId); if (m.find()) { String lPrefix = m.group(1).toString().trim(); String lHours = m.group(2).toString().trim(); ... |