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
    • Method Detail

      • getString

        public static final java.lang.String getString​(java.time.LocalDateTime localDateTime)
        Parameters:
        localDateTime - in format LocalDateTime to transform
        Returns:
        the ISO Date Time
      • getStringFormatted

        public static final java.lang.String getStringFormatted​(java.time.LocalDateTime localDateTime)
        Parameters:
        localDateTime - in format LocalDateTime to transform
        Returns:
        the ISO Date Time
      • getString

        public static java.lang.String getString​(java.util.Date date)
        Parameters:
        date - in format date to transform
        Returns:
        the ISO Date Time
      • now

        public static java.time.LocalDateTime now()
        Returns:
        the LocalDateTime now in UTC
      • 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.text.ParseException
        java.lang.IllegalArgumentException - date null or empty
      • fromMillis

        public static java.time.LocalDateTime fromMillis​(long millis)
        Parameters:
        millis - in format long to transform
        Returns:
        the corresponding LocalDateTime in UTC
      • getMillis

        public static long getMillis​(java.time.LocalDateTime ldt)
        Parameters:
        ldt - in format LocalDateTime to transform
        Returns:
        the millis in epoch
        Throws:
        java.lang.IllegalArgumentException - ldt null or empty
      • fromDate

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

        public static java.time.LocalDateTime fromDate​(java.nio.file.attribute.FileTime fileTime)
        Parameters:
        fileTime - in format FileTime 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)
        Parameters:
        date - localDate
        Returns:
        formatted date
      • getSimpleFormattedDate

        public static java.util.Date getSimpleFormattedDate​(java.lang.String date)
                                                     throws java.text.ParseException
        Parameters:
        date - date
        Returns:
        formatted date
        Throws:
        java.text.ParseException
      • getLocalDateFromSimpleFormattedDate

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

        public static java.lang.String getFormattedDateForMongo​(java.lang.String date)
        Use to have homogeneous String date format on database
        Parameters:
        date - 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)
      • 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
      • getFormattedDateForMongo

        public static java.lang.String getFormattedDateForMongo​(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
      • 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
      • getFormattedDateForEsIndexes

        public static java.lang.String getFormattedDateForEsIndexes​(java.time.LocalDateTime date)
        Use to have homogeneous String date format on ES indexes
        Parameters:
        date - 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
        Returns:
      • parseDate

        public static java.time.LocalDate parseDate​(java.lang.String endDateStr)
      • currentTimeMillis

        public static long currentTimeMillis()
      • getClock

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

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

        public static void resetClock()