# Class SimpleDateFormat

java.lang.Object
com.codename1.l10n.Format
com.codename1.l10n.DateFormat
com.codename1.l10n.SimpleDateFormat

All Implemented Interfaces:
  `Cloneable`

public class SimpleDateFormat extends DateFormat

A class for parsing and formatting dates with a given pattern, compatible with the Java 6 API, as in the examples here: https://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

To localize the formatted dates, see the discussion Format a localized date in Codename One.

- ## Field Summary

  ### Fields inherited from class DateFormat

  `DEFAULT, FULL, LONG, MEDIUM, SHORT`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SimpleDateFormat()`
  Construct a SimpleDateFormat with no pattern.
  `SimpleDateFormat(String pattern)`
  Construct a SimpleDateFormat with a given pattern.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `applyPattern(String pattern)`
  Apply a new pattern.
  `Object`
  `clone()`
  `boolean`
  `equals(Object o)`
  `String`
  `format(Date source)`
  Format a given date.
  `DateFormatSymbols`
  `getDateFormatSymbols()`
  Get the date format symbols for parsing/formatting textual components of dates in a localization sensitive way.
  `int`
  `hashCode()`
  `static boolean`
  `isRestrictMonthNameLength()`

  ###### Returns

  `Date`
  `parse(String source)`
  Parses text from a string to produce a Date.
  `void`
  `setDateFormatSymbols(DateFormatSymbols newSymbols)`
  Apply new date format symbols for parsing/formatting textual components of dates in a localisation sensitive way.
  `static void`
  `setRestrictMonthNameLength(boolean restrict)`
  Enables or disables truncating of localized month names so that they match the number of pattern characters that triggered their lookup.
  `String`
  `toPattern()`

  ###### Returns

  ### Methods inherited from class DateFormat

  `format, getDateInstance, getDateInstance, getDateTimeInstance, getInstance, getTimeInstance, getTimeInstance, parseObject`

  ### Methods inherited from class Object

  `finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### SimpleDateFormat

    public SimpleDateFormat()
    Construct a SimpleDateFormat with no pattern.

  - ### SimpleDateFormat

    public SimpleDateFormat(String pattern)

    Construct a SimpleDateFormat with a given pattern.

    ###### Parameters

    - `pattern`

- ## Method Details

  - ### isRestrictMonthNameLength

    public static boolean isRestrictMonthNameLength()

    ###### Returns

    Returns:
      `true` if localized month names should be truncated to the requested pattern length.

  - ### setRestrictMonthNameLength

    public static void setRestrictMonthNameLength(boolean restrict)

    Enables or disables truncating of localized month names so that they match the number of pattern characters that triggered their lookup.

    ###### Parameters

    - `restrict`: @param restrict `true` to truncate localized month names to the length requested by the pattern, `false` to keep the platform provided value as-is (default behaviour).

  - ### toPattern

    public String toPattern()

    ###### Returns

    the pattern

  - ### getDateFormatSymbols

    public DateFormatSymbols getDateFormatSymbols()

    Get the date format symbols for parsing/formatting textual components of dates in a localization sensitive way.

    ###### Returns

    current symbols.

  - ### setDateFormatSymbols

    public void setDateFormatSymbols(DateFormatSymbols newSymbols)

    Apply new date format symbols for parsing/formatting textual components of dates in a localisation sensitive way.

    ###### Parameters

    - `newSymbols`: new format symbols.

  - ### applyPattern

    public void applyPattern(String pattern)

    Apply a new pattern.

    ###### Parameters

    - `pattern`: the pattern to set

  - ### equals

    public boolean equals(Object o)
    Overrides:
      `equals` in class `DateFormat`

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `DateFormat`

  - ### clone

    public Object clone()
    Overrides:
      `clone` in class `DateFormat`

  - ### format

    public String format(Date source)
    Description copied from class: `DateFormat`

    Format a given date.

    ###### Parameters

    - `source`: date to be formatted.

    ###### Returns

    formatted date.

    Overrides:
      `format` in class `DateFormat`

  - ### parse

    public Date parse(String source) throws ParseException
    Parses text from a string to produce a Date.
    Overrides:
      `parse` in class `DateFormat`
    Throws:
      `ParseException`