Class JavaTimeConverters

java.lang.Object
com.ibm.icu.impl.JavaTimeConverters

@Deprecated public class JavaTimeConverters extends Object
Deprecated.
This API is ICU internal only.
This class provides utility methods for converting between Java 8's java.time classes and the Calendar and related classes from the com.ibm.icu.util package.

The class includes methods for converting various temporal types, such as ZonedDateTime, OffsetTime, OffsetDateTime, LocalTime, ChronoLocalDate, and ChronoLocalDateTime, to Calendar instances.

Additionally, it provides methods to convert between ZoneId and TimeZone, and ZoneOffset and TimeZone.

  • Field Details

  • Constructor Details

    • JavaTimeConverters

      private JavaTimeConverters()
      Deprecated.
  • Method Details

    • temporalToCalendar

      @Deprecated public static Calendar temporalToCalendar(ZonedDateTime dateTime)
      Deprecated.
      This API is ICU internal only.
      Converts a ZonedDateTime to a Calendar.

      This method creates a Calendar instance that represents the same date and time as the specified ZonedDateTime, taking into account the time zone information associated with the ZonedDateTime.

      Parameters:
      dateTime - The ZonedDateTime to convert.
      Returns:
      A Calendar instance representing the same date and time as the specified ZonedDateTime, with the time zone set accordingly.
    • temporalToCalendar

      @Deprecated public static Calendar temporalToCalendar(OffsetTime time)
      Deprecated.
      This API is ICU internal only.
      Converts an OffsetTime to a Calendar.

      This method creates a Calendar instance that represents the same time of day as the specified OffsetTime, taking into account the offset from UTC associated with the OffsetTime. The resulting Calendar will have its date components (year, month, day) set to the current date in the time zone represented by the offset.

      Parameters:
      time - The OffsetTime to convert.
      Returns:
      A Calendar instance representing the same time of day as the specified OffsetTime, with the time zone set accordingly and date components set to the current date in that time zone.
    • temporalToCalendar

      @Deprecated public static Calendar temporalToCalendar(OffsetDateTime dateTime)
      Deprecated.
      This API is ICU internal only.
      Converts an OffsetDateTime to a Calendar.

      This method creates a Calendar instance that represents the same date and time as the specified OffsetDateTime, taking into account the offset from UTC associated with the OffsetDateTime.

      Parameters:
      dateTime - The OffsetDateTime to convert.
      Returns:
      A Calendar instance representing the same date and time as the specified OffsetDateTime, with the time zone set accordingly.
    • temporalToCalendar

      @Deprecated static Calendar temporalToCalendar(ChronoLocalDate date)
      Deprecated.
      Converts a ChronoLocalDate to a Calendar.

      This method creates a Calendar instance that represents the same date as the specified ChronoLocalDate. The resulting Calendar will be in the default time zone of the JVM and will have its time components (hour, minute, second, millisecond) set to zero.

      Parameters:
      date - The ChronoLocalDate to convert.
      Returns:
      A Calendar instance representing the same date as the specified ChronoLocalDate, with time components set to zero.
    • temporalToCalendar

      @Deprecated public static Calendar temporalToCalendar(LocalTime time)
      Deprecated.
      This API is ICU internal only.
      Converts a LocalTime to a Calendar.

      This method creates a Calendar instance that represents the same time of day as the specified LocalTime. The resulting Calendar will be in the default time zone of the JVM and will have its date components (year, month, day) set to the current date in the default time zone.

      Parameters:
      time - The LocalTime to convert.
      Returns:
      A Calendar instance representing the same time of day as the specified LocalTime, with date components set to the current date in the default time zone.
    • temporalToCalendar

      @Deprecated public static Calendar temporalToCalendar(LocalDateTime dateTime)
      Deprecated.
      This API is ICU internal only.
      Converts a ChronoLocalDateTime to a Calendar.

      This method creates a Calendar instance that represents the same date and time as the specified ChronoLocalDateTime. The resulting Calendar will be in the default time zone of the JVM.

      Parameters:
      dateTime - The ChronoLocalDateTime to convert.
      Returns:
      A Calendar instance representing the same date and time as the specified ChronoLocalDateTime.
    • temporalToCalendar

      @Deprecated public static Calendar temporalToCalendar(Temporal temp)
      Deprecated.
      This API is ICU internal only.
      Converts a Temporal to a Calendar.
      Parameters:
      temp - The Temporal to convert.
      Returns:
      A Calendar instance representing the same date and time as the specified Temporal.
    • zoneIdToTimeZone

      @Deprecated public static TimeZone zoneIdToTimeZone(ZoneId zoneId)
      Deprecated.
      This API is ICU internal only.
      Converts a ZoneId to a TimeZone.

      This method creates a TimeZone from the specified ZoneId. The resulting TimeZone will represent the time zone rules associated with the given ZoneId.

      Parameters:
      zoneId - The zone ID to convert.
      Returns:
      A TimeZone representing the time zone rules associated with the given ZoneId.
    • zoneOffsetToTimeZone

      @Deprecated public static TimeZone zoneOffsetToTimeZone(ZoneOffset zoneOffset)
      Deprecated.
      This API is ICU internal only.
      Converts a ZoneOffset to a TimeZone.

      This method creates a TimeZone that has a fixed offset from UTC, represented by the given ZoneOffset.

      Parameters:
      zoneOffset - The zone offset to convert.
      Returns:
      A TimeZone that has a fixed offset from UTC, represented by the given ZoneOffset.
    • dayOfWeekToCalendar

      @Deprecated public static Calendar dayOfWeekToCalendar(DayOfWeek dow)
      Deprecated.
      This API is ICU internal only.
      Converts a DayOfWeek to a Calendar.

      This method creates a Calendar instance that represents a day that is the same day of week as specified by DayOfWeek. It is set somewhere close to epoch time.

      Note: this should only be used to format if using a pattern or skeleton with a day of week field only. That means that c-cccccc patterns are recommended, E-EEEEEE and e-eeeeee are likely wrong (because they are not stand-alone). Anything else is clearly wrong. It does not make sense to format a DayOfWeek as "MMMM d, y". See

      invalid @link
      {@link https://unicode.org/reports/tr35/tr35-dates.html#dfst-weekday
      }.
      Parameters:
      dow - The DayOfWeek to convert.
      Returns:
      A Calendar instance representing the same day of week as the one specified by the input.
    • monthToCalendar

      @Deprecated public static Calendar monthToCalendar(Month month)
      Deprecated.
      This API is ICU internal only.
      Converts a Month to a Calendar.

      This method creates a Calendar instance that represents the same month as specified by Month. It is set somewhere close to epoch time.

      Note: this should only be used to format if using a pattern or skeleton with a day of month field only. That means that L-LLLLL patterns are recommended, E-MMMMM is likely wrong (because it is not stand-alone). Anything else is clearly wrong. It does not make sense to format a Month as "MMMM d, y". See

      invalid @link
      {@link https://unicode.org/reports/tr35/tr35-dates.html#dfst-month
      }.

      Note: only use this method for the Gregorian calendar and related calendars, given that the Month documentation, states that the Month enum "... may be used by any calendar system that has the month-of-year concept defined equivalent to the ISO-8601 calendar system".

      Parameters:
      month - The Month to convert.
      Returns:
      A Calendar instance representing the same month as the one specified by the input.
    • millisToCalendar

      private static Calendar millisToCalendar(long epochMillis)
      Deprecated.
    • millisToCalendar

      private static Calendar millisToCalendar(long epochMillis, TimeZone timeZone)
      Deprecated.
    • dayOfWeekToMillis

      private static long dayOfWeekToMillis(DayOfWeek dow)
      Deprecated.
    • monthToMilli

      private static long monthToMilli(Month month)
      Deprecated.
    • convertCalendar

      @Deprecated public static Calendar convertCalendar(Calendar inputCalendar)
      Deprecated.
      This API is ICU internal only.
      Converts a Calendar to a Calendar.
      Parameters:
      inputCalendar - The JDK Calendar to convert.
      Returns:
      An ICU Calendar that has the same properties as the Java one.