org.springframework.format.datetime.standard

## Class DateTimeContextHolder

- java.lang.Object
- - org.springframework.format.datetime.standard.DateTimeContextHolder

-     public final class DateTimeContextHolder
      extends Object

  A holder for a thread-local user `DateTimeContext`.
  Since:
    4.0
  Author:
    Juergen Hoeller

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `DateTimeContextHolder()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static DateTimeContext` | `getDateTimeContext()` Return the DateTimeContext associated with the current thread, if any.
    `static java.time.format.DateTimeFormatter` | `getFormatter(java.time.format.DateTimeFormatter formatter, Locale locale)` Obtain a DateTimeFormatter with user-specific settings applied to the given base Formatter.
    `static void` | `resetDateTimeContext()` Reset the DateTimeContext for the current thread.
    `static void` | `setDateTimeContext(DateTimeContext dateTimeContext)` Associate the given DateTimeContext with the current thread.

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

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

- - ### Constructor Detail

    - #### DateTimeContextHolder

          public DateTimeContextHolder()

  - ### Method Detail

    - #### resetDateTimeContext

          public static void resetDateTimeContext()

      Reset the DateTimeContext for the current thread.

    - #### setDateTimeContext

          public static void setDateTimeContext(DateTimeContext dateTimeContext)

      Associate the given DateTimeContext with the current thread.
      Parameters:
        `dateTimeContext` - the current DateTimeContext, or `null` to reset the thread-bound context

    - #### getDateTimeContext

          public static DateTimeContext getDateTimeContext()

      Return the DateTimeContext associated with the current thread, if any.
      Returns:
        the current DateTimeContext, or `null` if none

    - #### getFormatter

          public static java.time.format.DateTimeFormatter getFormatter(java.time.format.DateTimeFormatter formatter,
                                                                        Locale locale)

      Obtain a DateTimeFormatter with user-specific settings applied to the given base Formatter.
      Parameters:
        `formatter` - the base formatter that establishes default formatting rules (generally user independent)
        `locale` - the current user locale (may be `null` if not known)
      Returns:
        the user-specific DateTimeFormatter