Class LocalDateUtil


  • public final class LocalDateUtil
    extends java.lang.Object
    LocalDateTime utilities
    • Field Detail

      • SIMPLE_DATE_FORMAT

        public static final java.lang.String SIMPLE_DATE_FORMAT
        See Also:
        Constant Field Values
      • LONG_SECOND_DATE_FORMAT

        public static final java.lang.String LONG_SECOND_DATE_FORMAT
        See Also:
        Constant Field Values
      • EPOCH

        public static java.time.LocalDateTime EPOCH
    • Method Detail

      • getString

        public static java.lang.String getString​(java.time.LocalDateTime localDateTime)
        Deprecated.
        Use getFormattedDateTimeForMongo
        Formats date/time in ISO_DATE_TIME. Seconds / milliseconds are truncated when 0
      • getStringFormatted

        public static java.lang.String getStringFormatted​(java.time.LocalDateTime localDateTime)
        Deprecated.
        Use getFormattedDateTimeForMongo
        Formats date/time in ISO_DATE_TIME. Seconds / milliseconds are truncated when 0
      • getString

        public static java.lang.String getString​(java.util.Date date)
        Deprecated.
        Use getFormattedDateTimeForMongo
        Formats date/time in ISO_DATE_TIME. Seconds / milliseconds are truncated when 0
      • now

        public static java.time.LocalDateTime now()
        Returns:
        the LocalDateTime now in UTC
      • nowFormatted

        public static java.lang.String nowFormatted()
        2024-12-25T12:00:00.000
      • getDate

        public static java.util.Date getDate​(java.lang.String date)
                                      throws java.text.ParseException
        Parameters:
        date - in format String to transform
        Returns:
        the corresponding Date from date string
        Throws:
        java.lang.IllegalArgumentException - date null or empty
        java.text.ParseException
      • fromDate

        public static java.time.LocalDateTime fromDate​(java.util.Date date)
        Parameters:
        date - in format Date to transform
        Returns:
        the corresponding LocalDateTime in UTC
      • getDate

        public static java.util.Date getDate​(java.time.LocalDateTime ldt)
        Parameters:
        ldt - in format LocalDateTime to transform
        Returns:
        the corresponding date
      • getFormattedDate

        public static java.lang.String getFormattedDate​(java.util.Date date)
        Parameters:
        date - date
        Returns:
        formatted date
      • getFormattedDate

        public static java.lang.String getFormattedDate​(java.time.LocalDateTime date)
        Parameters:
        date - date
        Returns:
        formatted date
      • getFormattedSimpleDate

        public static java.lang.String getFormattedSimpleDate​(java.util.Date date)
        Parameters:
        date - date
        Returns:
        formatted date
      • getFormattedSimpleDate

        public static java.lang.String getFormattedSimpleDate​(java.time.LocalDate date)
        2024-12-25
      • getLocalDateFromSimpleFormattedDate

        public static java.time.LocalDate getLocalDateFromSimpleFormattedDate​(java.lang.String date)
        Parameters:
        date - formatted date
        Returns:
        the corresponding LocalDate
      • getFormattedDateTimeForMongo

        public static java.lang.String getFormattedDateTimeForMongo​(java.lang.String dateTime)
        2016-09-27T12:34:56.123 2016-09-27T00:00:00.000 Use to have homogeneous String date format on database
        Parameters:
        dateTime - the date to format for database
        Returns:
        the formatted date for database
        Throws:
        java.time.format.DateTimeParseException - thrown when cannot parse String date (not ISO_LOCAL_DATE_TIME, not ZONED_DATE_TIME_FORMAT and not ISO_DATE date format)
      • getFormattedDateTimeForMongo

        public static java.lang.String getFormattedDateTimeForMongo​(java.time.LocalDateTime date)
        Use to have homogeneous String date format on database
        Parameters:
        date - the date to format for database
        Returns:
        the formatted date for database
      • getFormattedDateForMongo

        public static java.lang.String getFormattedDateForMongo​(java.lang.String dateTime)
        Deprecated.
        Use getFormattedDateTimeForMongo
      • getFormattedDateForMongo

        public static java.lang.String getFormattedDateForMongo​(java.time.LocalDateTime dateTime)
        Deprecated.
        Use getFormattedDateTimeForMongo
      • transformIsoOffsetDateToIsoOffsetDateTime

        public static java.lang.String transformIsoOffsetDateToIsoOffsetDateTime​(java.lang.String date)
        Transform ISO_OFFSET_DATE to ISO_OFFSET_DATE_TIME
        Parameters:
        date - the date to format for elastic
        Returns:
        the formatted date for elastic
      • parseMongoFormattedDate

        public static java.time.LocalDateTime parseMongoFormattedDate​(java.lang.String str)
        Parses a mongo formated date
        Parameters:
        str - formatted date in database
        Returns:
        the parsed local date time
      • parseDate

        public static java.time.LocalDate parseDate​(java.lang.String endDateStr)
        2024-12-25
      • getFormattedDateForEsIndexes

        public static java.lang.String getFormattedDateForEsIndexes​(java.time.LocalDateTime localDateTime)
        Use to have homogeneous String date format on ES indexes
        Parameters:
        localDateTime - the date to format for database
        Returns:
        the formatted date for database
      • getDateTimeFormatterForFileNames

        public static java.time.format.DateTimeFormatter getDateTimeFormatterForFileNames()
        return a DateTimeFormatter suitable for filename in the format yyyyMMddHHmmssSSS
      • getDateTimeFormatterForStorageTraceabilityFileNames

        public static java.time.format.DateTimeFormatter getDateTimeFormatterForStorageTraceabilityFileNames()
      • getDateTimeFormatterForStorageLogFileNames

        public static java.time.format.DateTimeFormatter getDateTimeFormatterForStorageLogFileNames()
      • currentTimeMillis

        public static long currentTimeMillis()
      • max

        public static java.time.LocalDateTime max​(java.time.LocalDateTime localDateTime1,
                                                  java.time.LocalDateTime localDateTime2)
      • parse

        public static java.time.LocalDateTime parse​(java.lang.String dateTimeStr,
                                                    java.time.format.DateTimeFormatter formatter)
      • fromEpochMilliUTC

        public static java.time.LocalDateTime fromEpochMilliUTC​(long epochMilli)
      • toEpochMilliUTC

        public static long toEpochMilliUTC​(java.time.LocalDateTime localDateTime)
      • getInstant

        public static java.time.Instant getInstant()
      • getClock

        public static java.time.Clock getClock()
      • setClock

        public static void setClock​(java.time.Clock clock)
      • resetClock

        public static void resetClock()