Package com.norconex.importer.util
Class FormatUtil
- java.lang.Object
-
- com.norconex.importer.util.FormatUtil
-
public final class FormatUtil extends Object
Utility methods related to formatting. Date formatting from string uses the US English locale when the locale is not specified. In addition to standard Java date format syntax, you can use the string "EPOCH" (ornull) to represent an EPOCH format.- Since:
- 2.2.0
- Author:
- Pascal Essiembre
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringformatDateString(String dateString, String fromFormat, String toFormat)Formats a string representation of a date, into another string date format.static StringformatDateString(String dateString, String fromFormat, String toFormat, String fieldName)Formats a string representation of a date, into another string date format.static StringformatDateString(String dateString, String fromFormat, Locale fromLocale, String toFormat, Locale toLocale, String subjectName)Formats a string representation of a date, into another string date format.static ZonedDateTimeparseZonedDateTimeString(String dateString, String fromFormat, Locale fromLocale, String subjectName, ZoneId zoneId)Formats a string representation of a date, into another string date format.
-
-
-
Method Detail
-
formatDateString
public static String formatDateString(String dateString, String fromFormat, String toFormat)
Formats a string representation of a date, into another string date format.- Parameters:
dateString- the date to formatfromFormat- source format (nullmeans EPOCH)toFormat- target format (nullmeans EPOCH)- Returns:
- formatted date string, or
nullif unable to format
-
formatDateString
public static String formatDateString(String dateString, String fromFormat, String toFormat, String fieldName)
Formats a string representation of a date, into another string date format.- Parameters:
dateString- the date to formatfromFormat- source formattoFormat- target formatfieldName- optional field name for referencing in error messages- Returns:
- formatted date string
-
formatDateString
public static String formatDateString(String dateString, String fromFormat, Locale fromLocale, String toFormat, Locale toLocale, String subjectName)
Formats a string representation of a date, into another string date format.- Parameters:
dateString- the date to formatfromFormat- source formatfromLocale- source format localetoFormat- target formattoLocale- target format localesubjectName- optional subject name to appear in error messages- Returns:
- formatted date string
- Since:
- 2.5.2
-
parseZonedDateTimeString
public static ZonedDateTime parseZonedDateTimeString(String dateString, String fromFormat, Locale fromLocale, String subjectName, ZoneId zoneId)
Formats a string representation of a date, into another string date format.- Parameters:
dateString- the date to formatfromFormat- source formatfromLocale- source format localesubjectName- optional subject name to appear in error messageszoneId- time zone id ornullto use system default or detected one if specified in format- Returns:
- a local date time or
nullif date string isnullor could not parse. - Since:
- 3.0.0
-
-