Class DateTimeUtils

java.lang.Object
org.hisp.dhis.util.DateTimeUtils

public class DateTimeUtils extends Object
  • Field Details

  • Constructor Details

    • DateTimeUtils

      public DateTimeUtils()
  • Method Details

    • getDate

      public static Date getDate(int year, int month, int dayOfMonth)
      Returns a date.
      Parameters:
      year - the year.
      month - the month, from 1.
      dayOfMonth - , from 1 to 31.
      Returns:
      a Date.
    • getDateString

      public static String getDateString(Date date)
      Returns a date string on the format: yyyy-MM-dd.
      Parameters:
      date - the Date.
      Returns:
      a date string.
    • getLocalDate

      public static LocalDate getLocalDate(String string)
      Returns a LocalDate based on the given string. The string must be on the ISO local date format, e.g. 2007-12-03.
      Parameters:
      string - the date string.
      Returns:
      a LocalDate.
    • getLocalDateString

      public static String getLocalDateString(LocalDate date)
      Returns a date string on the format: yyyy-MM-dd.
      Parameters:
      date - the LocalDate.
      Returns:
      a date time string.
    • isValidLocalDate

      public static boolean isValidLocalDate(String string)
      Indicates whether the given string can be parsed to a local date, i.e. is in a valid ISO date format, e.g. 2007-12-03.
      Parameters:
      string - the date string.
      Returns:
      true if the given string can be parsed to a local date, false otherwise.
    • getLocalDateTime

      public static LocalDateTime getLocalDateTime(String string)
      Returns a LocalDateTime based on the given string using the UTC time zone. The string must be on the ISO local date time format, e.g. 2007-12-03T10:15:30.00 or 2007-12-03T10:15:30.00Z. A trailing 'Z' indicating Zulu/UTC time will be ignored.
      Parameters:
      string - the instant string.
      Returns:
      a LocalDateTime.
    • getLocalDateTimeAsDate

      public static LocalDate getLocalDateTimeAsDate(String string)
      Returns a LocalDate based on the given string using the UTC time zone. The string must be on the ISO local date time format, e.g. 2007-12-03T10:15:30.00 or 2007-12-03T10:15:30.00Z. A trailing 'Z' indicating Zulu/UTC time will be ignored.
      Parameters:
      string - the instant string.
      Returns:
      a LocalDateTime.
    • isValidLocalDateTime

      public static boolean isValidLocalDateTime(String string)
      Indicates whether the given string can be parsed to a local date time, i.e. is in a valid ISO date time format, e.g. 2007-12-03T10:15:30.00Z.
      Parameters:
      string - the instant string.
      Returns:
      true if the given string can be parsed to a local date time, false otherwise.
    • getLocalDateTimeString

      public static String getLocalDateTimeString(LocalDateTime dateTime)
      Returns a date time string on the format: yyyy-MM-dd'T'HH:mm:ss.SSS.
      Parameters:
      dateTime - the LocalDateTime.
      Returns:
      a date time string.
    • getDateTimeString

      public static String getDateTimeString(Date dateTime)
      Returns a date time string on the format: yyyy-MM-dd'T'HH:mm:ss.SSS.
      Parameters:
      dateTime - the Date.
      Returns:
      a date time string.
    • getUtcDateTimeString

      public static String getUtcDateTimeString(LocalDateTime dateTime)
      Returns a date time string on the format: yyyy-MM-dd'T'HH:mm:ss.SSSZ.
      Parameters:
      dateTime - the LocalDateTime.
      Returns:
      a date time string.
    • getUtcDateTimeString

      public static String getUtcDateTimeString(Date dateTime)
      Returns a date time string on the format: yyyy-MM-dd'T'HH:mm:ss.SSSZ.
      Parameters:
      dateTime - the Date.
      Returns:
      a date time string.
    • toInstant

      public static Instant toInstant(Date date)
      Returns the Instant of received date param. if data is null, it also returns null Instant.
      Parameters:
      date - the Date.
      Returns:
      the Instant of received date param.
    • toLocalDate

      public static LocalDate toLocalDate(Instant instant)
      Returns the LocalDate from a given Instant.
      Parameters:
      instant - the Instant.
      Returns:
      the LocalDate.
    • toLocalDateTime

      public static LocalDateTime toLocalDateTime(Instant instant)
      Returns the LocalDateTime from a given Instant.
      Parameters:
      instant - the Instant.
      Returns:
      the LocalDateTime.
    • toDate

      public static Date toDate(LocalDate date)
      Returns a Date from a LocalDate.
      Parameters:
      date - the LocalDate.
      Returns:
      the Date.
    • toDate

      public static Date toDate(LocalDateTime dateTime)
      Returns a Date from a LocalDateTime.
      Parameters:
      dateTime - the LocalDateTime.
      Returns:
      the Date.
    • toLocalDate

      public static LocalDate toLocalDate(Date date)
      Converts the given Date to a LocalDate.
      Parameters:
      date - the Date.
      Returns:
      a LocalDate.
    • toLocalDateTime

      public static LocalDateTime toLocalDateTime(Date date)
      Converts the given Date to a LocalDateTime.
      Parameters:
      date - the Date.
      Returns:
      a LocalDateTime.