List of utility methods to do ZonedDateTime Calculate
ZonedDateTime | addOffset(ZonedDateTime time, String offset) Applies an ISO 8601 Duration to a ZonedDateTime . final int tPos = offset.indexOf('T'); final String periodOffset; final String durationOffset; switch (tPos) { case -1: periodOffset = offset; break; case 1: ... |
ZonedDateTime | addRandomDeltaDays(ZonedDateTime ZDT, int minDays, int maxDays, int minHour, int maxHour) Adds/substract randomly between minDays and maxDays number of days to this date and sets the hours within the range prescribed (min/maxHours), and a randomly selected minute between 0 and 60. if (ZDT == null) return null; int days = (int) Math.floor((Math.random() * (maxDays - minDays)) + minDays); int hours = (int) Math.floor((Math.random() * (maxHour - minHour)) + minHour); int minutes = (int) Math.floor((Math.random() * 60)); return ZDT.plusDays(days).withHour(hours).withMinute(minutes); |
ZonedDateTime | addRandomDeltaMinutes(ZonedDateTime ZDT, int minMinutes, int maxMinutes) Adds/substract randomly between min/maxMinutes number of minutes to this date. if (ZDT == null) return null; int minutes = (int) Math.round((Math.random() * (minMinutes - minMinutes)) + minMinutes); return ZDT.plusMinutes(minutes); |
ZonedDateTime | asZonedDateTime(Date date) Calls #asZonedDateTime(Date,ZoneId) with the system default time zone. return asZonedDateTime(date, ZoneId.systemDefault());
|
ZonedDateTime | calculateTimeForSunrise(ZonedDateTime from, ZonedDateTime to) calculate Time For Sunrise Duration d = Duration.between(from, to); long distance = d.getSeconds() / 60 / 60 / 2; return from.plusHours(distance); |
String | canonicalTimeString(ZonedDateTime time) ISO8601 can map the same date and time to many different string representations. ZonedDateTime asUTC = time.withZoneSameInstant(ZoneOffset.UTC);
return asUTC.format(canonicalFormatter);
|
ZonedDateTime | cloneZonedDateTime(ZonedDateTime zonedDateTime) clone Zoned Date Time if (zonedDateTime == null) { return null; return zonedDateTime.withZoneSameInstant(METZONE); |
int | computeDays(ZonedDateTime Start, ZonedDateTime End) Comput ethe number of days using th emidnight rule, i.e., from 23:59 Monday night to 00:01 Tuesday morning, that counts as one day. int days = (int) ChronoUnit.DAYS.between(Start, End); if (secondsSinceMidnight(Start) > secondsSinceMidnight(End)) ++days; return days; |
ZonedDateTime | convertDateToZonedDateTime(Date date, String timezone) convert Date To Zoned Date Time if (timezone == null || timezone.equals("")) { return date.toInstant().atZone(ZoneId.systemDefault()); return date.toInstant().atZone(ZoneId.of(timezone)); |
Date | convertForPersistence(@Nullable ZonedDateTime dt) Convert the given ZonedDateTime to a UTC date for persistence if (dt == null) return null; ZonedDateTime atUtc = dt.withZoneSameInstant(ZoneOffset.UTC); return new Date(atUtc.toInstant().toEpochMilli()); |