Java Utililty Methods ZonedDateTime Calculate

List of utility methods to do ZonedDateTime Calculate

Description

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

Method

ZonedDateTimetimestampToZonedDateTime(Long timestamp)
timestamp To Zoned Date Time
return Instant.ofEpochSecond(timestamp).atZone(ZoneOffset.UTC);
longtoEpochMillSeconds(ZonedDateTime time)
to Epoch Mill Seconds
long seconds;
if (time != null)
    seconds = time.toEpochSecond();
else
    seconds = 0;
return seconds;
longtoEpochTime(ZonedDateTime input)
to Epoch Time
if (input == null) {
    throw new IllegalArgumentException("Input time must not be null");
return input.toEpochSecond();
StringtoLocalDateString(ZonedDateTime zonedDateTime)
Converts a LocalDateTime to a UTC ISO_8601 string representation

e.g.

return zonedDateTime.withZoneSameInstant(ZoneOffset.UTC).toLocalDate().format(localDateFormatter);
OptionaltoUTCZonedDateTime(String dateString)
Converts any valid ZonedDateTime String (ISO_8601) representation to a UTC ZonedDateTime

e.g.

try {
    ZonedDateTime utcDateTime = ZonedDateTime.parse(dateString, dateTimeFormatterAny)
            .withZoneSameInstant(UTC);
    return Optional.of(utcDateTime);
} catch (DateTimeParseException ex) {
    return Optional.empty();
ZonedDateTimetoZeroMSN(ZonedDateTime dateTime)
to Zero MSN
return dateTime.withMinute(0).withSecond(0).withNano(0);
longuaDateTimeFromTime(ZonedDateTime time)
ua Date Time From Time
Instant i = Instant.from(time);
long seconds = i.getEpochSecond();
int nanoOfSecond = i.getNano();
long value = (UNIX_EPOCH_BIAS_SEC + seconds) * 10000000L + nanoOfSecond / 100L;
return value;
ZonedDateTimeYoungest(ZonedDateTime ZDT1, ZonedDateTime ZDT2)
Youngest
return ZDT1 == null ? ZDT2 : ZDT2 == null ? ZDT1 : ZDT1.compareTo(ZDT2) > 0 ? ZDT1 : ZDT2;
longzoneDateTime2long(final ZonedDateTime zdt)
convert ZonedDateTime to millisecond(long).
return zdt.toInstant().toEpochMilli();