spring-framework / org.springframework.format.datetime / DateFormatter

DateFormatter

open class DateFormatter : Formatter<Date>

A formatter for java.util.Date types. Allows the configuration of an explicit date pattern and locale.

Author
Keith Donald

Author
Juergen Hoeller

Author
Phillip Webb

Since
3.0

See Also
SimpleDateFormat

Constructors

<init>

DateFormatter()

Create a new default DateFormatter.

DateFormatter(pattern: String)

Create a new DateFormatter for the given date pattern.

Functions

parse

open fun parse(text: String, locale: Locale): Date

print

open fun print(date: Date, locale: Locale): String

setIso

open fun setIso(iso: ISO): Unit

Set the ISO format used for this date.

setLenient

open fun setLenient(lenient: Boolean): Unit

Specify whether or not parsing is to be lenient. Default is false.

With lenient parsing, the parser may allow inputs that do not precisely match the format. With strict parsing, inputs must match the format exactly.

setPattern

open fun setPattern(pattern: String): Unit

Set the pattern to use to format date values.

If not specified, DateFormat's default style will be used.

setStyle

open fun setStyle(style: Int): Unit

Set the style to use to format date values.

If not specified, DateFormat's default style will be used.

setStylePattern

open fun setStylePattern(stylePattern: String): Unit

Set the two character to use to format date values. The first character used for the date style, the second is for the time style. Supported characters are

  • 'S' = Small
  • 'M' = Medium
  • 'L' = Long
  • 'F' = Full
  • '-' = Omitted
    • This method mimics the styles supported by Joda-Time.

setTimeZone

open fun setTimeZone(timeZone: TimeZone): Unit

Set the TimeZone to normalize the date values into, if any.