Package org.springframework.format.datetime.standard

# Class DateTimeContext

java.lang.Object
org.springframework.format.datetime.standard.DateTimeContext

public class DateTimeContext extends Object
A context that holds user-specific `java.time` (JSR-310) settings such as the user's Chronology (calendar system) and time zone.

A `null` property value indicates the user has not specified a setting.

Since:
  4.0
Author:
  Juergen Hoeller
See Also:
  - `DateTimeContextHolder`

## Constructor Summary

Constructors
Constructor
Description
`DateTimeContext()`

## Method Summary

Modifier and Type
Method
Description
`Chronology`
`getChronology()`
Return the user's chronology (calendar system), if any.
`DateTimeFormatter`
`getFormatter(DateTimeFormatter formatter)`
Get the DateTimeFormatter with this context's settings applied to the base `formatter`.
`ZoneId`
`getTimeZone()`
Return the user's time zone, if any.
`void`
`setChronology(Chronology chronology)`
Set the user's chronology (calendar system).
`void`
`setTimeZone(ZoneId timeZone)`
Set the user's time zone.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### DateTimeContext

public DateTimeContext()

## Method Details

### setChronology

public void setChronology(@Nullable Chronology chronology)
Set the user's chronology (calendar system).

### getChronology

@Nullable public Chronology getChronology()
Return the user's chronology (calendar system), if any.

### setTimeZone

public void setTimeZone(@Nullable ZoneId timeZone)
Set the user's time zone.

Alternatively, set a `TimeZoneAwareLocaleContext` on `LocaleContextHolder`. This context class will fall back to checking the locale context if no setting has been provided here.

See Also:
  - `LocaleContextHolder.getTimeZone()`
  - `LocaleContextHolder.setLocaleContext(org.springframework.context.i18n.LocaleContext)`

### getTimeZone

@Nullable public ZoneId getTimeZone()
Return the user's time zone, if any.

### getFormatter

public DateTimeFormatter getFormatter(DateTimeFormatter formatter)
Get the DateTimeFormatter with this context's settings applied to the base `formatter`.

Parameters:
  `formatter` - the base formatter that establishes default formatting rules, generally context-independent
Returns:
  the contextual DateTimeFormatter