Package io.goobi.viewer.controller
Class DateTools
java.lang.Object
io.goobi.viewer.controller.DateTools
Utility methods for date parsing, etc.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DateTimeFormatterConstantformatterCNDate.static final DateTimeFormatterConstantformatterDEDate.static final DateTimeFormatterConstantformatterDEDateTime.static final DateTimeFormatterConstantformatterDEDateTimeNoSeconds.static final DateTimeFormatterConstantformatterUSDate.static final DateTimeFormatterConstantformatterENDateTime.static final DateTimeFormatterConstantformatterENDateTimeNoSeconds.static final DateTimeFormatterstatic final DateTimeFormatterConstantformatterISO8601BasicDate.static final DateTimeFormatterConstantformatterISO8601BasicDateNoYear.static final DateTimeFormatterConstantformatterBasicDateTime.static final DateTimeFormatterConstantformatterISO8601Date.static final DateTimeFormatterConstantformatterISO8601DateReverse.static final DateTimeFormatterConstantformatterISO8601DateTime.static final DateTimeFormatterConstantformatterISO8601DateTimeInstant.static final DateTimeFormatterConstantformatterISO8601DateTimeMS.static final DateTimeFormatterConstantformatterISO8601DateTimeNoSeconds.static final DateTimeFormatterConstantformatterISO8601DateTimeWithOffset.static final DateTimeFormatterConstantformatterISO8601Full.static final DateTimeFormatterConstantformatterISO8601Date.static final DateTimeFormatterConstantformatterISO8601YearMonth.static final DateTimeFormatterConstantformatterJavaUtilDateToString.static final DateTimeFormatterConstantformatterJPDate.static final DateTimeFormatterstatic final DateTimeFormatter -
Method Summary
Modifier and TypeMethodDescriptionstatic LocalDateTimeconvertDateToLocalDateTimeViaInstant(Date dateToConvert) static DateconvertLocalDateTimeToDateViaInstant(LocalDateTime dateToConvert, boolean utc) static Stringformat(LocalDateTime localDateTime, DateTimeFormatter formatter, boolean utc) static Stringformat(Date date, DateTimeFormatter formatter, boolean utc) static StringformatDate(LocalDateTime ldt, Locale locale) Converts the givenLocalDateTimeto a locale-based string format.static StringgetLocalDate(LocalDateTime date, String language) Returns the string representation of the givenDatebased on the given ISO 639-1 language code.static LocalDateTimegetLocalDateTimeFromMillis(long millis, boolean utc) static LonggetMillisFromLocalDateTime(LocalDateTime ldt, boolean utc) static LocalDateTimeparseDateFromString(String dateString) parseDateFromString.static LocalDateTimeparseDateTimeFromString(String dateString, boolean fromUTC) static LocalDateTimeparseDateTimeFromString(String dateString, boolean fromUTC, Integer zoneOffset) parseDateTimeFromString.static List<LocalDateTime> parseMultipleDatesFromString(String dateString) Converts the given string to a list of Date objects created from the contents of this string (years or whole dates).
-
Field Details
-
FORMATTERISO8601FULL
ConstantformatterISO8601Full. -
FORMATTERISO8601DATETIMEINSTANT
ConstantformatterISO8601DateTimeInstant. -
FORMATTERISO8601DATETIMEWITHOFFSET
ConstantformatterISO8601DateTimeWithOffset. -
FORMATTERISO8601DATE
ConstantformatterISO8601Date. -
FORMATTERISO8601TIME
ConstantformatterISO8601Date. -
FORMATTERISO8601DATEREVERSE
ConstantformatterISO8601DateReverse. -
FORMATTERISO8601YEARMONTH
ConstantformatterISO8601YearMonth. -
FORMATTERISO8601DATETIME
ConstantformatterISO8601DateTime. -
FORMATTERISO8601DATETIMEMS
ConstantformatterISO8601DateTimeMS. -
FORMATTERDEDATE
ConstantformatterDEDate. -
FORMATTERENDATE
ConstantformatterUSDate. -
FORMATTERCNDATE
ConstantformatterCNDate. -
FORMATTERJPDATE
ConstantformatterJPDate. -
FORMATTERISO8601DATETIMENOSECONDS
ConstantformatterISO8601DateTimeNoSeconds. -
FORMATTERDEDATETIME
ConstantformatterDEDateTime. -
FORMATTERENDATETIME
ConstantformatterENDateTime. -
FORMATTERDEDATETIMENOSECONDS
ConstantformatterDEDateTimeNoSeconds. -
FORMATTERENDATETIMENOSECONDS
ConstantformatterENDateTimeNoSeconds. -
FORMATTERISO8601BASICDATENOYEAR
ConstantformatterISO8601BasicDateNoYear. -
FORMATTERISO8601BASICDATE
ConstantformatterISO8601BasicDate. -
FORMATTERISO8601BASICDATETIME
ConstantformatterBasicDateTime. -
FORMATTERJAVAUTILDATETOSTRING
ConstantformatterJavaUtilDateToString. -
FORMATTERYEARONLY
-
FORMATTERMONTHDAYONLY
-
FORMATTERFILENAME
-
-
Method Details
-
parseMultipleDatesFromString
Converts the given string to a list of Date objects created from the contents of this string (years or whole dates).- Parameters:
dateString- raw date string to parse, may contain multiple dates separated by "/"- Returns:
- a list of LocalDateTime objects parsed from the given date string
-
getLocalDateTimeFromMillis
- Parameters:
millis- Epoch milliseconds to convertutc- If true, interprets the value as UTC; otherwise uses the system default timezone- Returns:
LocalDateTimebuilt from millis
-
getMillisFromLocalDateTime
- Parameters:
ldt- LocalDateTime to convert to epoch millisecondsutc- If true, treats the value as UTC; otherwise uses the system default timezone- Returns:
Longbuilt from ldt
-
parseDateTimeFromString
- Parameters:
dateString- Date/time string to parsefromUTC- If true, interprets the parsed date as UTC and converts to the system timezone- Returns:
LocalDateTimeparsed from dateString
-
parseDateTimeFromString
public static LocalDateTime parseDateTimeFromString(String dateString, boolean fromUTC, Integer zoneOffset) parseDateTimeFromString.- Parameters:
dateString- date/time string to parse in any supported formatfromUTC- if true, interprets the parsed date as UTCzoneOffset- Optional UTC hour offset to apply when converting from UTC; null uses system default- Returns:
- the parsed LocalDateTime, or null if the string cannot be parsed
-
parseDateFromString
parseDateFromString.- Parameters:
dateString- date string to parse using default (non-UTC) mode- Returns:
- the parsed date as LocalDateTime, or null if the string cannot be parsed
-
convertLocalDateTimeToDateViaInstant
-
convertDateToLocalDateTimeViaInstant
- Parameters:
dateToConvert-Dateto convert to aLocalDateTime- Returns:
LocalDateTimeconverted form dateToConvert
-
format
-
format
- Parameters:
localDateTime- LocalDateTime to formatformatter- Formatter to apply to the date/timeutc- If true, formats in UTC; otherwise uses the system default timezone- Returns:
- Formatted
LocalDateTimeasString
-
getLocalDate
Returns the string representation of the givenDatebased on the given ISO 639-1 language code.- Parameters:
date- LocalDateTime to format.language- ISO 639-1 (two-character) language code.- Returns:
- the date/time formatted as a locale-specific string based on the given language code
-
formatDate
Converts the givenLocalDateTimeto a locale-based string format. This method is used by the crowdsourcing module.- Parameters:
ldt- date/time value to formatlocale- locale determining the output date format- Returns:
- the date/time formatted as a locale-specific string, or null if ldt is null
-