Package fr.gouv.vitam.common

# Class LocalDateUtil

java.lang.Object
fr.gouv.vitam.common.LocalDateUtil

public final class LocalDateUtil extends Object
LocalDateTime utilities

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static LocalDateTime`
  `EPOCH`
  `static final String`
  `LONG_SECOND_DATE_FORMAT`
  `static final String`
  `SIMPLE_DATE_FORMAT`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static long`
  `currentTimeMillis()`
  `static LocalDateTime`
  `fromDate(Date date)`
  `static LocalDateTime`
  `fromEpochMilliUTC(long epochMilli)`
  `static Clock`
  `getClock()`
  `static Date`
  `getDate(String date)`
  `static Date`
  `getDate(LocalDateTime ldt)`
  `static DateTimeFormatter`
  `getDateTimeFormatterForFileNames()`
  return a DateTimeFormatter suitable for filename in the format yyyyMMddHHmmssSSS
  `static DateTimeFormatter`
  `getDateTimeFormatterForStorageLogFileNames()`
  `static DateTimeFormatter`
  `getDateTimeFormatterForStorageTraceabilityFileNames()`
  `static String`
  `getFormattedDate(LocalDateTime date)`
  `static String`
  `getFormattedDate(Date date)`
  `static String`
  `getFormattedDateForEsIndexes(LocalDateTime localDateTime)`
  Use to have homogeneous String date format on ES indexes
  `static String`
  `getFormattedDateForMongo(String dateTime)`
  Deprecated.
  Use getFormattedDateTimeForMongo
  `static String`
  `getFormattedDateForMongo(LocalDateTime dateTime)`
  Deprecated.
  Use getFormattedDateTimeForMongo
  `static String`
  `getFormattedDateOnlyForMongo(String date)`
  `static String`
  `getFormattedDateTimeForMongo(String dateTime)`
  2016-09-27T12:34:56.123 2016-09-27T00:00:00.000 Use to have homogeneous String date format on database
  `static String`
  `getFormattedDateTimeForMongo(LocalDateTime date)`
  Use to have homogeneous String date format on database
  `static String`
  `getFormattedSimpleDate(LocalDate date)`
  2024-12-25
  `static String`
  `getFormattedSimpleDate(Date date)`
  `static Instant`
  `getInstant()`
  `static LocalDate`
  `getLocalDateFromSimpleFormattedDate(String date)`
  `static String`
  `getString(LocalDateTime localDateTime)`
  Deprecated.
  Use getFormattedDateTimeForMongo
  `static String`
  `getString(Date date)`
  Deprecated.
  Use getFormattedDateTimeForMongo
  `static String`
  `getStringFormatted(LocalDateTime localDateTime)`
  Deprecated.
  Use getFormattedDateTimeForMongo
  `static LocalDateTime`
  `max(LocalDateTime localDateTime1, LocalDateTime localDateTime2)`
  `static LocalDateTime`
  `now()`
  2024-12-25T12:34:56:123 2024-12-25T12:00:00.000
  `static String`
  `nowFormatted()`
  2024-12-25T12:34:56:123 2024-12-25T12:00:00.000
  `static LocalDateTime`
  `parse(String dateTimeStr, DateTimeFormatter formatter)`
  `static LocalDate`
  `parseDate(String endDateStr)`
  2024-12-25
  `static LocalDateTime`
  `parseMongoFormattedDate(String str)`
  Parses a mongo formated date
  `static void`
  `resetClock()`
  `static void`
  `setClock(Clock clock)`
  `static LocalDate`
  `today()`
  2024-12-25 2024-12-25
  `static String`
  `todayFormatted()`
  2024-12-25
  `static long`
  `toEpochMilliUTC(LocalDateTime localDateTime)`
  `static String`
  `transformIsoOffsetDateToIsoOffsetDateTime(String date)`
  Transform ISO_OFFSET_DATE to ISO_OFFSET_DATE_TIME

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### SIMPLE_DATE_FORMAT

    public static final String SIMPLE_DATE_FORMAT
    See Also:
      - Constant Field Values

  - ### LONG_SECOND_DATE_FORMAT

    public static final String LONG_SECOND_DATE_FORMAT
    See Also:
      - Constant Field Values

  - ### EPOCH

    public static LocalDateTime EPOCH

- ## Method Details

  - ### getString

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

  - ### getStringFormatted

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

  - ### getString

    public static String getString(Date date)
    Deprecated.
    Use getFormattedDateTimeForMongo
    Formats date/time in ISO_DATE_TIME. Seconds / milliseconds are truncated when 0

  - ### now

    public static LocalDateTime now()
    2024-12-25T12:34:56:123 2024-12-25T12:00:00.000
    Returns:
      the LocalDateTime now in UTC

  - ### today

    public static LocalDate today()
    2024-12-25 2024-12-25
    Returns:
      the LocalDate today in UTC

  - ### nowFormatted

    public static String nowFormatted()
    2024-12-25T12:34:56:123 2024-12-25T12:00:00.000

  - ### todayFormatted

    public static String todayFormatted()
    2024-12-25

  - ### getDate

    public static Date getDate(String date) throws ParseException
    Parameters:
      `date` - in format String to transform
    Returns:
      the corresponding Date from date string
    Throws:
      `IllegalArgumentException` - date null or empty
      `ParseException`

  - ### fromDate

    public static LocalDateTime fromDate(Date date)
    Parameters:
      `date` - in format Date to transform
    Returns:
      the corresponding LocalDateTime in UTC

  - ### getDate

    public static Date getDate(LocalDateTime ldt)
    Parameters:
      `ldt` - in format LocalDateTime to transform
    Returns:
      the corresponding date

  - ### getFormattedDate

    public static String getFormattedDate(Date date)
    Parameters:
      `date` - date
    Returns:
      formatted date

  - ### getFormattedDate

    public static String getFormattedDate(LocalDateTime date)
    Parameters:
      `date` - date
    Returns:
      formatted date

  - ### getFormattedSimpleDate

    public static String getFormattedSimpleDate(Date date)
    Parameters:
      `date` - date
    Returns:
      formatted date

  - ### getFormattedSimpleDate

    public static String getFormattedSimpleDate(LocalDate date)
    2024-12-25

  - ### getLocalDateFromSimpleFormattedDate

    public static LocalDate getLocalDateFromSimpleFormattedDate(String date)
    Parameters:
      `date` - formatted date
    Returns:
      the corresponding LocalDate

  - ### getFormattedDateTimeForMongo

    public static String getFormattedDateTimeForMongo(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:
      `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 String getFormattedDateTimeForMongo(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 String getFormattedDateForMongo(String dateTime)
    Deprecated.
    Use getFormattedDateTimeForMongo

  - ### getFormattedDateOnlyForMongo

    public static String getFormattedDateOnlyForMongo(String date)

  - ### getFormattedDateForMongo

    public static String getFormattedDateForMongo(LocalDateTime dateTime)
    Deprecated.
    Use getFormattedDateTimeForMongo

  - ### transformIsoOffsetDateToIsoOffsetDateTime

    public static String transformIsoOffsetDateToIsoOffsetDateTime(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 LocalDateTime parseMongoFormattedDate(String str)
    Parses a mongo formated date
    Parameters:
      `str` - formatted date in database
    Returns:
      the parsed local date time

  - ### parseDate

    public static LocalDate parseDate(String endDateStr)
    2024-12-25

  - ### getFormattedDateForEsIndexes

    public static String getFormattedDateForEsIndexes(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 DateTimeFormatter getDateTimeFormatterForFileNames()
    return a DateTimeFormatter suitable for filename in the format yyyyMMddHHmmssSSS

  - ### getDateTimeFormatterForStorageTraceabilityFileNames

    public static DateTimeFormatter getDateTimeFormatterForStorageTraceabilityFileNames()

  - ### getDateTimeFormatterForStorageLogFileNames

    public static DateTimeFormatter getDateTimeFormatterForStorageLogFileNames()

  - ### currentTimeMillis

    public static long currentTimeMillis()

  - ### max

    public static LocalDateTime max(LocalDateTime localDateTime1, LocalDateTime localDateTime2)

  - ### parse

    public static LocalDateTime parse(String dateTimeStr, DateTimeFormatter formatter)

  - ### fromEpochMilliUTC

    public static LocalDateTime fromEpochMilliUTC(long epochMilli)

  - ### toEpochMilliUTC

    public static long toEpochMilliUTC(LocalDateTime localDateTime)

  - ### getInstant

    public static Instant getInstant()

  - ### getClock

    public static Clock getClock()

  - ### setClock

    public static void setClock(Clock clock)

  - ### resetClock

    public static void resetClock()