# DateFormat

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Ctors](https://developer.android.com/reference/android/text/format/DateFormat#pubctors)\|[Methods](https://developer.android.com/reference/android/text/format/DateFormat#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/text/format/DateFormat#inhmethods)  

# DateFormat

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/text/format/DateFormat "View this page in Kotlin")\|Java

`
public


class
DateFormat
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|--------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.text.format.DateFormat |

<br />

*** ** * ** ***

Utility class for producing strings with formatted date/time.

Most callers should avoid supplying their own format strings to this class'`format`methods and rely on the correctly localized ones supplied by the system. This class' factory methods return appropriately-localized[DateFormat](https://developer.android.com/reference/java/text/DateFormat)instances, suitable for both formatting and parsing dates. For the canonical documentation of format strings, see[SimpleDateFormat](https://developer.android.com/reference/java/text/SimpleDateFormat).

In cases where the system does not provide a suitable pattern, this class offers the[getBestDateTimePattern(Locale, String)](https://developer.android.com/reference/android/text/format/DateFormat#getBestDateTimePattern(java.util.Locale,%20java.lang.String))method.

The`format`methods in this class implement a subset of Unicode[UTS #35](http://www.unicode.org/reports/tr35/#Date_Format_Patterns)patterns. The subset currently supported by this class includes the following format characters:`acdEHhLKkLMmsyz`. Up to API level 17, only`adEhkMmszy`were supported. Note that this class incorrectly implements`k`as if it were`H`for backwards compatibility.

See[SimpleDateFormat](https://developer.android.com/reference/java/text/SimpleDateFormat)for more documentation about patterns, or if you need a more complete or correct implementation. Note that the non-`format`methods in this class are implemented by`SimpleDateFormat`.

## Summary

|                                           ### Public constructors                                            ||
|-----------------------------------------------------------------------------------------------------------|---|
| ` `[DateFormat](https://developer.android.com/reference/android/text/format/DateFormat#DateFormat())`() ` |

|                                                                                                                                                                                                                                                                                ### Public methods                                                                                                                                                                                                                                                                                ||
|------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | ` `[format](https://developer.android.com/reference/android/text/format/DateFormat#format(java.lang.CharSequence,%20java.util.Calendar))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` inFormat, `[Calendar](https://developer.android.com/reference/java/util/Calendar)` inDate) ` Given a format string and a[Calendar](https://developer.android.com/reference/java/util/Calendar)object, returns a CharSequence containing the requested date. |
| ` static `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | ` `[format](https://developer.android.com/reference/android/text/format/DateFormat#format(java.lang.CharSequence,%20java.util.Date))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` inFormat, `[Date](https://developer.android.com/reference/java/util/Date)` inDate) ` Given a format string and a[Date](https://developer.android.com/reference/java/util/Date)object, returns a CharSequence containing the requested date.                     |
| ` static `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | ` `[format](https://developer.android.com/reference/android/text/format/DateFormat#format(java.lang.CharSequence,%20long))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` inFormat, long inTimeInMillis) ` Given a format string and a time in milliseconds since Jan 1, 1970 GMT, returns a CharSequence containing the requested date.                                                                                                            |
| ` static `[String](https://developer.android.com/reference/java/lang/String)             | ` `[getBestDateTimePattern](https://developer.android.com/reference/android/text/format/DateFormat#getBestDateTimePattern(java.util.Locale,%20java.lang.String))`(`[Locale](https://developer.android.com/reference/java/util/Locale)` locale, `[String](https://developer.android.com/reference/java/lang/String)` skeleton) ` Returns the best possible localized form of the given skeleton for the given locale.                                                                   |
| ` static `[DateFormat](https://developer.android.com/reference/java/text/DateFormat)     | ` `[getDateFormat](https://developer.android.com/reference/android/text/format/DateFormat#getDateFormat(android.content.Context))`(`[Context](https://developer.android.com/reference/android/content/Context)` context) ` Returns a[DateFormat](https://developer.android.com/reference/java/text/DateFormat)object that can format the date in short form according to the context's locale.                                                                                         |
| ` static char[]`                                                                         | ` `[getDateFormatOrder](https://developer.android.com/reference/android/text/format/DateFormat#getDateFormatOrder(android.content.Context))`(`[Context](https://developer.android.com/reference/android/content/Context)` context) ` Gets the current date format stored as a char array.                                                                                                                                                                                              |
| ` static `[DateFormat](https://developer.android.com/reference/java/text/DateFormat)     | ` `[getLongDateFormat](https://developer.android.com/reference/android/text/format/DateFormat#getLongDateFormat(android.content.Context))`(`[Context](https://developer.android.com/reference/android/content/Context)` context) ` Returns a[DateFormat](https://developer.android.com/reference/java/text/DateFormat)object that can format the date in long form (such as`Monday, January 3, 2000`) for the context's locale.                                                        |
| ` static `[DateFormat](https://developer.android.com/reference/java/text/DateFormat)     | ` `[getMediumDateFormat](https://developer.android.com/reference/android/text/format/DateFormat#getMediumDateFormat(android.content.Context))`(`[Context](https://developer.android.com/reference/android/content/Context)` context) ` Returns a[DateFormat](https://developer.android.com/reference/java/text/DateFormat)object that can format the date in medium form (such as`Jan 3, 2000`) for the context's locale.                                                              |
| ` static `[DateFormat](https://developer.android.com/reference/java/text/DateFormat)     | ` `[getTimeFormat](https://developer.android.com/reference/android/text/format/DateFormat#getTimeFormat(android.content.Context))`(`[Context](https://developer.android.com/reference/android/content/Context)` context) ` Returns a[DateFormat](https://developer.android.com/reference/java/text/DateFormat)object that can format the time according to the context's locale and the user's 12-/24-hour clock preference.                                                           |
| ` static boolean`                                                                        | ` `[is24HourFormat](https://developer.android.com/reference/android/text/format/DateFormat#is24HourFormat(android.content.Context))`(`[Context](https://developer.android.com/reference/android/content/Context)` context) ` Returns true if times should be formatted as 24 hour times, false if times should be formatted as 12 hour (AM/PM) times.                                                                                                                                  |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public constructors

### DateFormat

```
public DateFormat ()
```

<br />

<br />

## Public methods

### format

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static CharSequence format (CharSequence inFormat, 
                Calendar inDate)
```

Given a format string and a[Calendar](https://developer.android.com/reference/java/util/Calendar)object, returns a CharSequence containing the requested date.

<br />

|                                                                        Parameters                                                                         ||
|------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| `inFormat` | `CharSequence`: the format string, as described in[DateFormat](https://developer.android.com/reference/android/text/format/DateFormat) <br /> |
| `inDate`   | `Calendar`: the date to format <br />                                                                                                         |

|                                                                                               Returns                                                                                               ||
|--------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|
| [CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | a[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)containing the requested text <br /> |

### format

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static CharSequence format (CharSequence inFormat, 
                Date inDate)
```

Given a format string and a[Date](https://developer.android.com/reference/java/util/Date)object, returns a CharSequence containing the requested date.

<br />

|                                                                        Parameters                                                                         ||
|------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| `inFormat` | `CharSequence`: the format string, as described in[DateFormat](https://developer.android.com/reference/android/text/format/DateFormat) <br /> |
| `inDate`   | `Date`: the date to format <br />                                                                                                             |

|                                                                                               Returns                                                                                               ||
|--------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|
| [CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | a[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)containing the requested text <br /> |

### format

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static CharSequence format (CharSequence inFormat, 
                long inTimeInMillis)
```

Given a format string and a time in milliseconds since Jan 1, 1970 GMT, returns a CharSequence containing the requested date.

<br />

|                                                                           Parameters                                                                            ||
|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| `inFormat`       | `CharSequence`: the format string, as described in[DateFormat](https://developer.android.com/reference/android/text/format/DateFormat) <br /> |
| `inTimeInMillis` | `long`: in milliseconds since Jan 1, 1970 GMT <br />                                                                                          |

|                                                                                               Returns                                                                                               ||
|--------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|
| [CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | a[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)containing the requested text <br /> |

### getBestDateTimePattern

Added in[API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static String getBestDateTimePattern (Locale locale, 
                String skeleton)
```

Returns the best possible localized form of the given skeleton for the given locale. A skeleton is similar to, and uses the same format characters as, a Unicode[UTS #35](http://www.unicode.org/reports/tr35/#Date_Format_Patterns)pattern.

One difference is that order is irrelevant. For example, "MMMMd" will return "MMMM d" in the`en_US`locale, but "d. MMMM" in the`de_CH`locale.

Note also in that second example that the necessary punctuation for German was added. For the same input in`es_ES`, we'd have even more extra text: "d 'de' MMMM".

This method will automatically correct for grammatical necessity. Given the same "MMMMd" input, this method will return "d LLLL" in the`fa_IR`locale, where stand-alone months are necessary. Lengths are preserved where meaningful, so "Md" would give a different result to "MMMd", say, except in a locale such as`ja_JP`where there is only one length of month.

This method will only return patterns that are in CLDR, and is useful whenever you know what elements you want in your format string but don't want to make your code specific to any one locale.

<br />

|                                     Parameters                                      ||
|------------|-------------------------------------------------------------------------|
| `locale`   | `Locale`: the locale into which the skeleton should be localized <br /> |
| `skeleton` | `String`: a skeleton as described above <br />                          |

|                                                                                                 Returns                                                                                                  ||
|--------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | a string pattern suitable for use with[SimpleDateFormat](https://developer.android.com/reference/java/text/SimpleDateFormat). <br /> |

### getDateFormat

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static DateFormat getDateFormat (Context context)
```

Returns a[DateFormat](https://developer.android.com/reference/java/text/DateFormat)object that can format the date in short form according to the context's locale.

<br />

|                      Parameters                      ||
|-----------|-------------------------------------------|
| `context` | `Context`: the application context <br /> |

|                                                                                                Returns                                                                                                 ||
|----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
| [DateFormat](https://developer.android.com/reference/java/text/DateFormat) | the[DateFormat](https://developer.android.com/reference/java/text/DateFormat)object that properly formats the date. <br /> |

### getDateFormatOrder

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static char[] getDateFormatOrder (Context context)
```

Gets the current date format stored as a char array. Returns a 3 element array containing the day (`'d'`), month (`'M'`), and year (`'y'`)) in the order specified by the user's format preference. Note that this order is*only*appropriate for all-numeric dates; spelled-out (MEDIUM and LONG) dates will generally contain other punctuation, spaces, or words, not just the day, month, and year, and not necessarily in the same order returned here.

<br />

|         Parameters          ||
|-----------|------------------|
| `context` | `Context` <br /> |

|     Returns      ||
|----------|--------|
| `char[]` | <br /> |

### getLongDateFormat

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static DateFormat getLongDateFormat (Context context)
```

Returns a[DateFormat](https://developer.android.com/reference/java/text/DateFormat)object that can format the date in long form (such as`Monday, January 3, 2000`) for the context's locale.

<br />

|                      Parameters                      ||
|-----------|-------------------------------------------|
| `context` | `Context`: the application context <br /> |

|                                                                                                  Returns                                                                                                   ||
|----------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
| [DateFormat](https://developer.android.com/reference/java/text/DateFormat) | the[DateFormat](https://developer.android.com/reference/java/text/DateFormat)object that formats the date in long form. <br /> |

### getMediumDateFormat

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static DateFormat getMediumDateFormat (Context context)
```

Returns a[DateFormat](https://developer.android.com/reference/java/text/DateFormat)object that can format the date in medium form (such as`Jan 3, 2000`) for the context's locale.

<br />

|                      Parameters                      ||
|-----------|-------------------------------------------|
| `context` | `Context`: the application context <br /> |

|                                                                                                  Returns                                                                                                   ||
|----------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
| [DateFormat](https://developer.android.com/reference/java/text/DateFormat) | the[DateFormat](https://developer.android.com/reference/java/text/DateFormat)object that formats the date in long form. <br /> |

### getTimeFormat

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static DateFormat getTimeFormat (Context context)
```

Returns a[DateFormat](https://developer.android.com/reference/java/text/DateFormat)object that can format the time according to the context's locale and the user's 12-/24-hour clock preference.

<br />

|                      Parameters                      ||
|-----------|-------------------------------------------|
| `context` | `Context`: the application context <br /> |

|                                                                                                Returns                                                                                                 ||
|----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
| [DateFormat](https://developer.android.com/reference/java/text/DateFormat) | the[DateFormat](https://developer.android.com/reference/java/text/DateFormat)object that properly formats the time. <br /> |

### is24HourFormat

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static boolean is24HourFormat (Context context)
```

Returns true if times should be formatted as 24 hour times, false if times should be formatted as 12 hour (AM/PM) times. Based on the user's chosen locale and other preferences.

<br />

|                                Parameters                                ||
|-----------|---------------------------------------------------------------|
| `context` | `Context`: the context to use for the content resolver <br /> |

|                                   Returns                                   ||
|-----------|------------------------------------------------------------------|
| `boolean` | true if 24 hour time format is selected, false otherwise. <br /> |