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.lang.StringLONG_SECOND_DATE_FORMATstatic java.lang.StringSIMPLE_DATE_FORMAT
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static longcurrentTimeMillis()static java.time.LocalDateTimefromDate(java.nio.file.attribute.FileTime fileTime)static java.time.LocalDateTimefromDate(java.util.Date date)static java.time.LocalDateTimefromMillis(long millis)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.lang.StringgetFormattedDate(java.time.LocalDateTime date)static java.lang.StringgetFormattedDate(java.util.Date date)static java.lang.StringgetFormattedDateForEsIndexes(java.time.LocalDateTime date)Use to have homogeneous String date format on ES indexesstatic java.lang.StringgetFormattedDateForMongo(java.lang.String date)Use to have homogeneous String date format on databasestatic java.lang.StringgetFormattedDateForMongo(java.time.LocalDateTime date)Use to have homogeneous String date format on databasestatic java.lang.StringgetFormattedSimpleDate(java.time.LocalDate date)static java.lang.StringgetFormattedSimpleDate(java.util.Date date)static java.time.InstantgetInstant()static java.time.LocalDategetLocalDateFromSimpleFormattedDate(java.lang.String date)static java.util.DategetSimpleFormattedDate(java.lang.String date)static java.lang.StringgetString(java.time.LocalDateTime localDateTime)static java.lang.StringgetString(java.util.Date date)static java.lang.StringgetStringFormatted(java.time.LocalDateTime localDateTime)static java.time.LocalDateTimemax(java.time.LocalDateTime localDateTime1, java.time.LocalDateTime localDateTime2)static java.time.LocalDateTimenow()static java.time.LocalDateparseDate(java.lang.String endDateStr)static java.time.LocalDateTimeparseMongoFormattedDate(java.lang.String str)Parses a mongo formated datestatic voidresetClock()static voidsetClock(java.time.Clock clock)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
-
-
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.ParseExceptionjava.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
-
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()
-
max
public static java.time.LocalDateTime max(java.time.LocalDateTime localDateTime1, java.time.LocalDateTime localDateTime2)
-
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()
-
-