Class TimeUtils

java.lang.Object
org.litebridge.commons.TimeUtils

public final class TimeUtils extends Object
Utility class for converting and formatting date and time objects.
  • Method Details

    • toZonedDateTime

      public static @Nullable ZonedDateTime toZonedDateTime(@Nullable String dateStr)
      Converts a date-time string to a ZonedDateTime.
      Parameters:
      dateStr - the date-time string to parse; may be null
      Returns:
      the parsed ZonedDateTime, or null if dateStr is null
    • toZonedDateTime

      public static @Nullable ZonedDateTime toZonedDateTime(@Nullable Date requestedDate)
      Converts a Date to a ZonedDateTime using the system default time zone.
      Parameters:
      requestedDate - the date to convert; may be null
      Returns:
      the corresponding ZonedDateTime, or null if requestedDate is null
    • toZonedDateTime

      public static @Nullable ZonedDateTime toZonedDateTime(@Nullable LocalDateTime localDateTime)
      Converts a LocalDateTime to a ZonedDateTime using the system default time zone.
      Parameters:
      localDateTime - the local date-time to convert; may be null
      Returns:
      the corresponding ZonedDateTime, or null if localDateTime is null
    • toZonedDateTime

      public static @Nullable ZonedDateTime toZonedDateTime(@Nullable LocalDate localDate)
      Converts a LocalDate to a ZonedDateTime at the start of the day in the system default time zone.
      Parameters:
      localDate - the local date to convert; may be null
      Returns:
      the corresponding ZonedDateTime, or null if localDate is null
    • toDate

      public static @Nullable Date toDate(@Nullable ZonedDateTime zonedDateTime)
      Converts a ZonedDateTime to a Date.
      Parameters:
      zonedDateTime - the zoned date-time to convert; may be null
      Returns:
      the corresponding Date, or null if zonedDateTime is null
    • toDate

      public static @Nullable Date toDate(@Nullable LocalDate localDate)
      Converts a LocalDate to a Date at the start of the day in the system default time zone.
      Parameters:
      localDate - the local date to convert; may be null
      Returns:
      the corresponding Date, or null if localDate is null
    • toDate

      public static @Nullable Date toDate(@Nullable LocalDateTime localDateTime)
      Converts a LocalDateTime to a Date in the system default time zone.
      Parameters:
      localDateTime - the local date-time to convert; may be null
      Returns:
      the corresponding Date, or null if localDateTime is null
    • toLocalDate

      public static @Nullable LocalDate toLocalDate(@Nullable ZonedDateTime zonedDateTime)
      Converts a ZonedDateTime to a LocalDate.
      Parameters:
      zonedDateTime - the zoned date-time to convert; may be null
      Returns:
      the corresponding LocalDate, or null if zonedDateTime is null
    • toLocalDate

      public static @Nullable LocalDate toLocalDate(@Nullable String dateStr)
      Converts a date string to a LocalDate.
      Parameters:
      dateStr - the date string to parse; may be null
      Returns:
      the parsed LocalDate, or null if dateStr is null
    • toLocalDateTime

      public static @Nullable LocalDateTime toLocalDateTime(@Nullable ZonedDateTime zonedDateTime)
      Converts a ZonedDateTime to a LocalDateTime in the system default time zone.
      Parameters:
      zonedDateTime - the zoned date-time to convert; may be null
      Returns:
      the corresponding LocalDateTime, or null if zonedDateTime is null
    • toLocalDateTime

      public static @Nullable LocalDateTime toLocalDateTime(@Nullable String dateStr)
      Converts a date-time string to a LocalDateTime.
      Parameters:
      dateStr - the date-time string to parse; may be null
      Returns:
      the parsed LocalDateTime, or null if dateStr is null
    • format

      public static String format(Temporal dateToFormat, String pattern)
      Formats the given temporal object using the specified pattern.
      Parameters:
      dateToFormat - the temporal object to format
      pattern - the pattern to use for formatting
      Returns:
      the formatted date-time string