Java Utililty Methods OffsetDateTime

List of utility methods to do OffsetDateTime

Description

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

Method

OffsetDateTimenowAtZone(String offsetId)
now At Zone
return nowAtZone(ZoneOffset.of(offsetId));
DateparseDate(String raw)
parse Date
return Date.from(OffsetDateTime.parse(fixOffset(raw)).toInstant());
StringstringifyDate(long timestamp)
stringify Date
return stringifyDate(
        OffsetDateTime.ofInstant(Instant.ofEpochMilli(timestamp), TimeZone.getTimeZone("GMT").toZoneId()));
StringtimeF(OffsetDateTime time, ZoneId zone)
time F
return time.atZoneSameInstant(zone).format(DateTimeFormatter.ISO_LOCAL_TIME).substring(0, 8);
CalendartoCalendar(OffsetDateTime offsetDateTime)
Convert the given OffsetDateTime instance to Calendar instance with the same time and time zone
Objects.requireNonNull(offsetDateTime, "Offset date time is required");
TimeZone timeZone = TimeZone.getTimeZone(offsetDateTime.toZonedDateTime().getZone());
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(offsetDateTime.toInstant().toEpochMilli());
calendar.setTimeZone(timeZone);
return calendar;
StringtoRfc1123String(FileTime time)
to Rfc String
final Temporal date = OffsetDateTime.ofInstant(time.toInstant(), ZoneOffset.UTC);
return DateTimeFormatter.RFC_1123_DATE_TIME.format(date);