# DateTimeFormatter

# DateTimeFormatter

Artifact:[androidx.core:core-i18n](https://developer.android.com/jetpack/androidx/releases/core)  
[View Source](https://cs.android.com/search?q=file:androidx/core/i18n/DateTimeFormatter.kt+class:androidx.core.i18n.DateTimeFormatter)  
Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/core#1.0.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/core/i18n/DateTimeFormatter "View this page in Java")

<br />

```
class DateTimeFormatter
```

<br />

*** ** * ** ***

DateTimeFormatter is a class for international-aware date/time formatting.

It is designed to encourage best i18n practices, and work correctly on old / new Android versions, without having to test the API level everywhere.

## Summary

|                                                                                                                                                                                                                                                                         ### Public constructors                                                                                                                                                                                                                                                                         |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [DateTimeFormatter](https://developer.android.com/reference/kotlin/androidx/core/i18n/DateTimeFormatter#DateTimeFormatter(androidx.core.i18n.DateTimeFormatterJdkStyleOptions,java.util.Locale))`(` ` options: `[DateTimeFormatterJdkStyleOptions](https://developer.android.com/reference/kotlin/androidx/core/i18n/DateTimeFormatterJdkStyleOptions)`,` ` locale: `[Locale](https://developer.android.com/reference/java/util/Locale.html) `)`                                                                                                                        |
| [DateTimeFormatter](https://developer.android.com/reference/kotlin/androidx/core/i18n/DateTimeFormatter#DateTimeFormatter(android.content.Context,androidx.core.i18n.DateTimeFormatterSkeletonOptions,java.util.Locale))`(` ` context: `[Context](https://developer.android.com/reference/android/content/Context.html)`,` ` options: `[DateTimeFormatterSkeletonOptions](https://developer.android.com/reference/kotlin/androidx/core/i18n/DateTimeFormatterSkeletonOptions)`,` ` locale: `[Locale](https://developer.android.com/reference/java/util/Locale.html) `)` |

|                               ### Public functions                                |
|-----------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | [format](https://developer.android.com/reference/kotlin/androidx/core/i18n/DateTimeFormatter#format(java.util.Calendar))`(calendar: `[Calendar](https://developer.android.com/reference/java/util/Calendar.html)`)` Formats a Calendar object into a user friendly locale aware date/time string. |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | [format](https://developer.android.com/reference/kotlin/androidx/core/i18n/DateTimeFormatter#format(java.util.Date))`(date: `[Date](https://developer.android.com/reference/java/util/Date.html)`)` Formats a Date object into a user friendly locale aware date/time string.                     |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | [format](https://developer.android.com/reference/kotlin/androidx/core/i18n/DateTimeFormatter#format(kotlin.Long))`(milliseconds: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Formats an epoch time into a user friendly, locale aware, date/time string.    |

## Public constructors

### DateTimeFormatter

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/core#1.0.0)  

```
DateTimeFormatter(
    options: DateTimeFormatterJdkStyleOptions,
    locale: Locale = getDefaultFormattingLocale()
)
```  

### DateTimeFormatter

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/core#1.0.0)  

```
DateTimeFormatter(
    context: Context,
    options: DateTimeFormatterSkeletonOptions,
    locale: Locale = getDefaultFormattingLocale()
)
```  

## Public functions

### format

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/core#1.0.0)  

```
fun format(calendar: Calendar): String
```

Formats a Calendar object into a user friendly locale aware date/time string.  

|                                       Parameters                                        |
|-----------------------------------------------------------------------------------------|----------------------------|
| `calendar: `[Calendar](https://developer.android.com/reference/java/util/Calendar.html) | the date / time to format. |

|                                      Returns                                      |
|-----------------------------------------------------------------------------------|-----------------------------------|
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | the formatted date / time string. |

### format

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/core#1.0.0)  

```
fun format(date: Date): String
```

Formats a Date object into a user friendly locale aware date/time string.  

|                                 Parameters                                  |
|-----------------------------------------------------------------------------|----------------------------|
| `date: `[Date](https://developer.android.com/reference/java/util/Date.html) | the date / time to format. |

|                                      Returns                                      |
|-----------------------------------------------------------------------------------|-----------------------------------|
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | the formatted date / time string. |

### format

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/core#1.0.0)  

```
fun format(milliseconds: Long): String
```

Formats an epoch time into a user friendly, locale aware, date/time string.  

|                                          Parameters                                           |
|-----------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|
| `milliseconds: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | the date / time to format expressed in milliseconds since January 1, 1970, 00:00:00 GMT. |

|                                      Returns                                      |
|-----------------------------------------------------------------------------------|-----------------------------------|
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | the formatted date / time string. |