Package fr.gouv.vitam.common
Class LocalDateUtil
- java.lang.Object
-
- fr.gouv.vitam.common.LocalDateUtil
-
public final class LocalDateUtil extends java.lang.ObjectLocalDateTime utilities
-
-
Field Summary
Fields Modifier and Type Field Description static java.time.LocalDateTimeEPOCHstatic java.lang.StringLONG_SECOND_DATE_FORMATstatic java.lang.StringSIMPLE_DATE_FORMAT
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static longcurrentTimeMillis()static java.time.LocalDateTimefromDate(java.util.Date date)static java.time.LocalDateTimefromEpochMilliUTC(long epochMilli)static java.time.ClockgetClock()static java.util.DategetDate(java.lang.String date)static java.util.DategetDate(java.time.LocalDateTime ldt)static java.time.format.DateTimeFormattergetDateTimeFormatterForFileNames()return a DateTimeFormatter suitable for filename in the format yyyyMMddHHmmssSSSstatic java.time.format.DateTimeFormattergetDateTimeFormatterForStorageLogFileNames()static java.time.format.DateTimeFormattergetDateTimeFormatterForStorageTraceabilityFileNames()static java.lang.StringgetFormattedDate(java.time.LocalDateTime date)static java.lang.StringgetFormattedDate(java.util.Date date)static java.lang.StringgetFormattedDateForEsIndexes(java.time.LocalDateTime localDateTime)Use to have homogeneous String date format on ES indexesstatic java.lang.StringgetFormattedDateForMongo(java.lang.String dateTime)Deprecated.Use getFormattedDateTimeForMongostatic java.lang.StringgetFormattedDateForMongo(java.time.LocalDateTime dateTime)Deprecated.Use getFormattedDateTimeForMongostatic java.lang.StringgetFormattedDateTimeForMongo(java.lang.String dateTime)2016-09-27T12:34:56.123 2016-09-27T00:00:00.000 Use to have homogeneous String date format on databasestatic java.lang.StringgetFormattedDateTimeForMongo(java.time.LocalDateTime date)Use to have homogeneous String date format on databasestatic java.lang.StringgetFormattedSimpleDate(java.time.LocalDate date)2024-12-25static java.lang.StringgetFormattedSimpleDate(java.util.Date date)static java.time.InstantgetInstant()static java.time.LocalDategetLocalDateFromSimpleFormattedDate(java.lang.String date)static java.lang.StringgetString(java.time.LocalDateTime localDateTime)Deprecated.Use getFormattedDateTimeForMongostatic java.lang.StringgetString(java.util.Date date)Deprecated.Use getFormattedDateTimeForMongostatic java.lang.StringgetStringFormatted(java.time.LocalDateTime localDateTime)Deprecated.Use getFormattedDateTimeForMongostatic java.time.LocalDateTimemax(java.time.LocalDateTime localDateTime1, java.time.LocalDateTime localDateTime2)static java.time.LocalDateTimenow()static java.lang.StringnowFormatted()2024-12-25T12:00:00.000static java.time.LocalDateTimeparse(java.lang.String dateTimeStr, java.time.format.DateTimeFormatter formatter)static java.time.LocalDateparseDate(java.lang.String endDateStr)2024-12-25static java.time.LocalDateTimeparseMongoFormattedDate(java.lang.String str)Parses a mongo formated datestatic voidresetClock()static voidsetClock(java.time.Clock clock)static longtoEpochMilliUTC(java.time.LocalDateTime localDateTime)static java.lang.StringtransformIsoOffsetDateToIsoOffsetDateTime(java.lang.String date)Transform ISO_OFFSET_DATE to ISO_OFFSET_DATE_TIME
-
-
-
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 getFormattedDateTimeForMongoFormats 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 getFormattedDateTimeForMongoFormats 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 getFormattedDateTimeForMongoFormats 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 emptyjava.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()
-
-