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

# DateUtils

*** ** * ** ***

` public class DateUtils `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

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

<br />

*** ** * ** ***

This class contains various date-related utilities for creating text for things like elapsed time and date ranges, strings for days of the week and months, and AM/PM text etc.

## Summary

| ### Constants ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/text/format/DateUtils#ABBREV_MONTH_FORMAT` *This constant was deprecated in API level 17. Use `https://developer.android.com/reference/java/text/SimpleDateFormat` instead.* |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/text/format/DateUtils#ABBREV_WEEKDAY_FORMAT` <br /> |
| `long` | `https://developer.android.com/reference/android/text/format/DateUtils#DAY_IN_MILLIS` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_12HOUR` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_24HOUR` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_ABBREV_ALL` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_ABBREV_MONTH` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_ABBREV_RELATIVE` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_ABBREV_TIME` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_ABBREV_WEEKDAY` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_CAP_AMPM` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_CAP_MIDNIGHT` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_CAP_NOON` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_CAP_NOON_MIDNIGHT` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_NO_MIDNIGHT` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_NO_MONTH_DAY` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_NO_NOON` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_NO_NOON_MIDNIGHT` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_NO_YEAR` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_NUMERIC_DATE` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_SHOW_DATE` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_SHOW_TIME` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_SHOW_WEEKDAY` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_SHOW_YEAR` <br /> |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_UTC` *This constant was deprecated in API level 15. Use `https://developer.android.com/reference/android/text/format/DateUtils#formatDateRange(android.content.Context,%20java.util.Formatter,%20long,%20long,%20int,%20java.lang.String)` and pass in `https://developer.android.com/reference/android/text/format/Time#TIMEZONE_UTC` for the timeZone instead.* |
| `long` | `https://developer.android.com/reference/android/text/format/DateUtils#HOUR_IN_MILLIS` <br /> |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/text/format/DateUtils#HOUR_MINUTE_24` *This constant was deprecated in API level 17. Use `https://developer.android.com/reference/java/text/SimpleDateFormat` instead.* |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#LENGTH_LONG` *This constant was deprecated in API level 17. Use `https://developer.android.com/reference/java/text/SimpleDateFormat` instead.* |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#LENGTH_MEDIUM` *This constant was deprecated in API level 17. Use `https://developer.android.com/reference/java/text/SimpleDateFormat` instead.* |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#LENGTH_SHORT` *This constant was deprecated in API level 17. Use `https://developer.android.com/reference/java/text/SimpleDateFormat` instead.* |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#LENGTH_SHORTER` *This constant was deprecated in API level 17. Use `https://developer.android.com/reference/java/text/SimpleDateFormat` instead.* |
| `int` | `https://developer.android.com/reference/android/text/format/DateUtils#LENGTH_SHORTEST` *This constant was deprecated in API level 17. Use `https://developer.android.com/reference/java/text/SimpleDateFormat` instead.* |
| `long` | `https://developer.android.com/reference/android/text/format/DateUtils#MINUTE_IN_MILLIS` <br /> |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/text/format/DateUtils#MONTH_DAY_FORMAT` <br /> |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/text/format/DateUtils#MONTH_FORMAT` <br /> |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/text/format/DateUtils#NUMERIC_MONTH_FORMAT` <br /> |
| `long` | `https://developer.android.com/reference/android/text/format/DateUtils#SECOND_IN_MILLIS` <br /> |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/text/format/DateUtils#WEEKDAY_FORMAT` <br /> |
| `long` | `https://developer.android.com/reference/android/text/format/DateUtils#WEEK_IN_MILLIS` <br /> |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/text/format/DateUtils#YEAR_FORMAT` <br /> |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/text/format/DateUtils#YEAR_FORMAT_TWO_DIGITS` <br /> |
| `long` | `https://developer.android.com/reference/android/text/format/DateUtils#YEAR_IN_MILLIS` *This constant was deprecated in API level 30. Not all years have the same number of days, and this constant is actually the length of 364 days. Please use other date/time constructs such as `https://developer.android.com/reference/java/util/concurrent/TimeUnit`, `https://developer.android.com/reference/java/util/Calendar` or `https://developer.android.com/reference/java/time/Duration` instead.* |

| ### Fields ||
|---|---|
| ` public static final int[]` | `https://developer.android.com/reference/android/text/format/DateUtils#sameMonthTable` *This field was deprecated in API level 17. Do not use.* |
| ` public static final int[]` | `https://developer.android.com/reference/android/text/format/DateUtils#sameYearTable` *This field was deprecated in API level 17. Do not use.* |

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

| ### Public methods ||
|---|---|
| ` static https://developer.android.com/reference/java/util/Formatter` | ` https://developer.android.com/reference/android/text/format/DateUtils#formatDateRange(android.content.Context,%20java.util.Formatter,%20long,%20long,%20int,%20java.lang.String)(https://developer.android.com/reference/android/content/Context context, https://developer.android.com/reference/java/util/Formatter formatter, long startMillis, long endMillis, int flags, https://developer.android.com/reference/java/lang/String timeZone) ` Formats a date or a time range according to the local conventions. |
| ` static https://developer.android.com/reference/java/util/Formatter` | ` https://developer.android.com/reference/android/text/format/DateUtils#formatDateRange(android.content.Context,%20java.util.Formatter,%20long,%20long,%20int)(https://developer.android.com/reference/android/content/Context context, https://developer.android.com/reference/java/util/Formatter formatter, long startMillis, long endMillis, int flags) ` Formats a date or a time range according to the local conventions. |
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/text/format/DateUtils#formatDateRange(android.content.Context,%20long,%20long,%20int)(https://developer.android.com/reference/android/content/Context context, long startMillis, long endMillis, int flags) ` Formats a date or a time range according to the local conventions. |
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/text/format/DateUtils#formatDateTime(android.content.Context,%20long,%20int)(https://developer.android.com/reference/android/content/Context context, long millis, int flags) ` Formats a date or a time according to the local conventions. |
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/text/format/DateUtils#formatElapsedTime(java.lang.StringBuilder,%20long)(https://developer.android.com/reference/java/lang/StringBuilder recycle, long elapsedSeconds) ` Formats an elapsed time in a format like "MM:SS" or "H:MM:SS" (using a form suited to the current locale), similar to that used on the call-in-progress screen. |
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/text/format/DateUtils#formatElapsedTime(long)(long elapsedSeconds) ` Formats an elapsed time in the form "MM:SS" or "H:MM:SS" for display on the call-in-progress screen. |
| ` static final https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/text/format/DateUtils#formatSameDayTime(long,%20long,%20int,%20int)(long then, long now, int dateStyle, int timeStyle) ` Format a date / time such that if the then is on the same day as now, it shows just the time and if it's a different day, it shows just the date. |
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/text/format/DateUtils#getAMPMString(int)(int ampm) ` *This method was deprecated in API level 17. Use `https://developer.android.com/reference/java/text/SimpleDateFormat` instead.* |
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/text/format/DateUtils#getDayOfWeekString(int,%20int)(int dayOfWeek, int abbrev) ` *This method was deprecated in API level 17. Use `https://developer.android.com/reference/java/text/SimpleDateFormat` instead.* |
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/text/format/DateUtils#getMonthString(int,%20int)(int month, int abbrev) ` *This method was deprecated in API level 17. Use `https://developer.android.com/reference/java/text/SimpleDateFormat` instead.* |
| ` static https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/text/format/DateUtils#getRelativeDateTimeString(android.content.Context,%20long,%20long,%20long,%20int)(https://developer.android.com/reference/android/content/Context c, long time, long minResolution, long transitionResolution, int flags) ` Return string describing the elapsed time since startTime formatted like "\[relative time/date\], \[time\]". |
| ` static https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/text/format/DateUtils#getRelativeTimeSpanString(android.content.Context,%20long,%20boolean)(https://developer.android.com/reference/android/content/Context c, long millis, boolean withPreposition) ` |
| ` static https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/text/format/DateUtils#getRelativeTimeSpanString(long,%20long,%20long,%20int)(long time, long now, long minResolution, int flags) ` Returns a string describing 'time' as a time relative to 'now'. |
| ` static https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/text/format/DateUtils#getRelativeTimeSpanString(long)(long startTime) ` Returns a string describing the elapsed time since startTime. |
| ` static https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/text/format/DateUtils#getRelativeTimeSpanString(android.content.Context,%20long)(https://developer.android.com/reference/android/content/Context c, long millis) ` Convenience function to return relative time string without preposition. |
| ` static https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/text/format/DateUtils#getRelativeTimeSpanString(long,%20long,%20long)(long time, long now, long minResolution) ` Returns a string describing 'time' as a time relative to 'now'. |
| ` static boolean` | ` https://developer.android.com/reference/android/text/format/DateUtils#isToday(long)(long when) ` |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` 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 https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` 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` ` 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` ` 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*.

## Constants

### ABBREV_MONTH_FORMAT

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

```
public static final String ABBREV_MONTH_FORMAT
```

<br />

**This constant was deprecated in API level 17.**   

Use `https://developer.android.com/reference/java/text/SimpleDateFormat` instead.

This is not actually a useful month name in all locales.

<br />

Constant Value: "%b"

### ABBREV_WEEKDAY_FORMAT

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

```
public static final String ABBREV_WEEKDAY_FORMAT
```

<br />

<br />

Constant Value: "%a"

### DAY_IN_MILLIS

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

```
public static final long DAY_IN_MILLIS
```

<br />

<br />

Constant Value: 86400000 (0x0000000005265c00)

### FORMAT_12HOUR

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

```
public static final int FORMAT_12HOUR
```

<br />

<br />

Constant Value: 64 (0x00000040)

### FORMAT_24HOUR

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

```
public static final int FORMAT_24HOUR
```

<br />

<br />

Constant Value: 128 (0x00000080)

### FORMAT_ABBREV_ALL

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

```
public static final int FORMAT_ABBREV_ALL
```

<br />

<br />

Constant Value: 524288 (0x00080000)

### FORMAT_ABBREV_MONTH

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

```
public static final int FORMAT_ABBREV_MONTH
```

<br />

<br />

Constant Value: 65536 (0x00010000)

### FORMAT_ABBREV_RELATIVE

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

```
public static final int FORMAT_ABBREV_RELATIVE
```

<br />

<br />

Constant Value: 262144 (0x00040000)

### FORMAT_ABBREV_TIME

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

```
public static final int FORMAT_ABBREV_TIME
```

<br />

<br />

Constant Value: 16384 (0x00004000)

### FORMAT_ABBREV_WEEKDAY

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

```
public static final int FORMAT_ABBREV_WEEKDAY
```

<br />

<br />

Constant Value: 32768 (0x00008000)

### FORMAT_CAP_AMPM

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

```
public static final int FORMAT_CAP_AMPM
```

<br />

<br />

Constant Value: 256 (0x00000100)

### FORMAT_CAP_MIDNIGHT

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

```
public static final int FORMAT_CAP_MIDNIGHT
```

<br />

<br />

Constant Value: 4096 (0x00001000)

### FORMAT_CAP_NOON

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

```
public static final int FORMAT_CAP_NOON
```

<br />

<br />

Constant Value: 1024 (0x00000400)

### FORMAT_CAP_NOON_MIDNIGHT

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

```
public static final int FORMAT_CAP_NOON_MIDNIGHT
```

<br />

<br />

Constant Value: 5120 (0x00001400)

### FORMAT_NO_MIDNIGHT

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

```
public static final int FORMAT_NO_MIDNIGHT
```

<br />

<br />

Constant Value: 2048 (0x00000800)

### FORMAT_NO_MONTH_DAY

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

```
public static final int FORMAT_NO_MONTH_DAY
```

<br />

<br />

Constant Value: 32 (0x00000020)

### FORMAT_NO_NOON

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

```
public static final int FORMAT_NO_NOON
```

<br />

<br />

Constant Value: 512 (0x00000200)

### FORMAT_NO_NOON_MIDNIGHT

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

```
public static final int FORMAT_NO_NOON_MIDNIGHT
```

<br />

<br />

Constant Value: 2560 (0x00000a00)

### FORMAT_NO_YEAR

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

```
public static final int FORMAT_NO_YEAR
```

<br />

<br />

Constant Value: 8 (0x00000008)

### FORMAT_NUMERIC_DATE

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

```
public static final int FORMAT_NUMERIC_DATE
```

<br />

<br />

Constant Value: 131072 (0x00020000)

### FORMAT_SHOW_DATE

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

```
public static final int FORMAT_SHOW_DATE
```

<br />

<br />

Constant Value: 16 (0x00000010)

### FORMAT_SHOW_TIME

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

```
public static final int FORMAT_SHOW_TIME
```

<br />

<br />

Constant Value: 1 (0x00000001)

### FORMAT_SHOW_WEEKDAY

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

```
public static final int FORMAT_SHOW_WEEKDAY
```

<br />

<br />

Constant Value: 2 (0x00000002)

### FORMAT_SHOW_YEAR

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

```
public static final int FORMAT_SHOW_YEAR
```

<br />

<br />

Constant Value: 4 (0x00000004)

### FORMAT_UTC

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

```
public static final int FORMAT_UTC
```

<br />

**This constant was deprecated in API level 15.**   

Use `https://developer.android.com/reference/android/text/format/DateUtils#formatDateRange(android.content.Context,%20java.util.Formatter,%20long,%20long,%20int,%20java.lang.String)` and pass in `https://developer.android.com/reference/android/text/format/Time#TIMEZONE_UTC` for the timeZone instead.

<br />

<br />

Constant Value: 8192 (0x00002000)

### HOUR_IN_MILLIS

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

```
public static final long HOUR_IN_MILLIS
```

<br />

<br />

Constant Value: 3600000 (0x000000000036ee80)

### HOUR_MINUTE_24

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

```
public static final String HOUR_MINUTE_24
```

<br />

**This constant was deprecated in API level 17.**   

Use `https://developer.android.com/reference/java/text/SimpleDateFormat` instead.

This is not actually the preferred 24-hour date format in all locales.

<br />

Constant Value: "%H:%M"

### LENGTH_LONG

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

```
public static final int LENGTH_LONG
```

<br />

**This constant was deprecated in API level 17.**   

Use `https://developer.android.com/reference/java/text/SimpleDateFormat` instead.

Request the full spelled-out name. For use with the 'abbrev' parameter of `https://developer.android.com/reference/android/text/format/DateUtils#getDayOfWeekString(int,%20int)` and `https://developer.android.com/reference/android/text/format/DateUtils#getMonthString(int,%20int)`.

<br />

Constant Value: 10 (0x0000000a)

### LENGTH_MEDIUM

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

```
public static final int LENGTH_MEDIUM
```

<br />

**This constant was deprecated in API level 17.**   

Use `https://developer.android.com/reference/java/text/SimpleDateFormat` instead.

Request an abbreviated version of the name. For use with the 'abbrev' parameter of `https://developer.android.com/reference/android/text/format/DateUtils#getDayOfWeekString(int,%20int)` and `https://developer.android.com/reference/android/text/format/DateUtils#getMonthString(int,%20int)`.

<br />

Constant Value: 20 (0x00000014)

### LENGTH_SHORT

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

```
public static final int LENGTH_SHORT
```

<br />

**This constant was deprecated in API level 17.**   

Use `https://developer.android.com/reference/java/text/SimpleDateFormat` instead.

Request a shorter abbreviated version of the name. For use with the 'abbrev' parameter of `https://developer.android.com/reference/android/text/format/DateUtils#getDayOfWeekString(int,%20int)` and `https://developer.android.com/reference/android/text/format/DateUtils#getMonthString(int,%20int)`.

<br />

Constant Value: 30 (0x0000001e)

### LENGTH_SHORTER

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

```
public static final int LENGTH_SHORTER
```

<br />

**This constant was deprecated in API level 17.**   

Use `https://developer.android.com/reference/java/text/SimpleDateFormat` instead.

Request an even shorter abbreviated version of the name. Do not use this. Currently this will always return the same result as `https://developer.android.com/reference/android/text/format/DateUtils#LENGTH_SHORT`.

<br />

Constant Value: 40 (0x00000028)

### LENGTH_SHORTEST

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

```
public static final int LENGTH_SHORTEST
```

<br />

**This constant was deprecated in API level 17.**   

Use `https://developer.android.com/reference/java/text/SimpleDateFormat` instead.

Request an even shorter abbreviated version of the name. For use with the 'abbrev' parameter of `https://developer.android.com/reference/android/text/format/DateUtils#getDayOfWeekString(int,%20int)` and `https://developer.android.com/reference/android/text/format/DateUtils#getMonthString(int,%20int)`.

<br />

Constant Value: 50 (0x00000032)

### MINUTE_IN_MILLIS

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

```
public static final long MINUTE_IN_MILLIS
```

<br />

<br />

Constant Value: 60000 (0x000000000000ea60)

### MONTH_DAY_FORMAT

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

```
public static final String MONTH_DAY_FORMAT
```

<br />

<br />

Constant Value: "%-d"

### MONTH_FORMAT

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

```
public static final String MONTH_FORMAT
```

<br />

<br />

Constant Value: "%B"

### NUMERIC_MONTH_FORMAT

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

```
public static final String NUMERIC_MONTH_FORMAT
```

<br />

<br />

Constant Value: "%m"

### SECOND_IN_MILLIS

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

```
public static final long SECOND_IN_MILLIS
```

<br />

<br />

Constant Value: 1000 (0x00000000000003e8)

### WEEKDAY_FORMAT

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

```
public static final String WEEKDAY_FORMAT
```

<br />

<br />

Constant Value: "%A"

### WEEK_IN_MILLIS

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

```
public static final long WEEK_IN_MILLIS
```

<br />

<br />

Constant Value: 604800000 (0x00000000240c8400)

### YEAR_FORMAT

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

```
public static final String YEAR_FORMAT
```

<br />

<br />

Constant Value: "%Y"

### YEAR_FORMAT_TWO_DIGITS

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

```
public static final String YEAR_FORMAT_TWO_DIGITS
```

<br />

<br />

Constant Value: "%g"

### YEAR_IN_MILLIS

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

```
public static final long YEAR_IN_MILLIS
```

<br />

**This constant was deprecated in API level 30.**   

Not all years have the same number of days, and this constant is actually the length of 364 days. Please use other date/time constructs such as `https://developer.android.com/reference/java/util/concurrent/TimeUnit`, `https://developer.android.com/reference/java/util/Calendar` or `https://developer.android.com/reference/java/time/Duration` instead.

<br />

<br />

Constant Value: 31449600000 (0x00000007528ad000)

## Fields

### sameMonthTable

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

```
public static final int[] sameMonthTable
```

<br />

**This field was deprecated in API level 17.**   

Do not use.

<br />

<br />

### sameYearTable

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

```
public static final int[] sameYearTable
```

<br />

**This field was deprecated in API level 17.**   

Do not use.

<br />

<br />

## Public constructors

### DateUtils

```
public DateUtils ()
```

<br />

<br />

## Public methods

### formatDateRange

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

```
public static Formatter formatDateRange (Context context, 
                Formatter formatter, 
                long startMillis, 
                long endMillis, 
                int flags, 
                String timeZone)
```

Formats a date or a time range according to the local conventions.

Example output strings (date formats in these examples are shown using the US date format convention but that may change depending on the local settings):

- 10:15am
- 3:00pm - 4:00pm
- 3pm - 4pm
- 3PM - 4PM
- 08:00 - 17:00
- Oct 9
- Tue, Oct 9
- October 9, 2007
- Oct 9 - 10
- Oct 9 - 10, 2007
- Oct 28 - Nov 3, 2007
- Dec 31, 2007 - Jan 1, 2008
- Oct 9, 8:00am - Oct 10, 5:00pm
- 12/31/2007 - 01/01/2008

The flags argument is a bitmask of options from the following list:

- FORMAT_SHOW_TIME
- FORMAT_SHOW_WEEKDAY
- FORMAT_SHOW_YEAR
- FORMAT_SHOW_DATE
- FORMAT_NO_MONTH_DAY
- FORMAT_12HOUR
- FORMAT_24HOUR
- FORMAT_CAP_AMPM
- FORMAT_NO_NOON
- FORMAT_CAP_NOON
- FORMAT_NO_MIDNIGHT
- FORMAT_CAP_MIDNIGHT
- FORMAT_UTC
- FORMAT_ABBREV_TIME
- FORMAT_ABBREV_WEEKDAY
- FORMAT_ABBREV_MONTH
- FORMAT_ABBREV_ALL
- FORMAT_NUMERIC_DATE

If FORMAT_SHOW_TIME is set, the time is shown as part of the date range. If the start and end time are the same, then just the start time is shown.

If FORMAT_SHOW_WEEKDAY is set, then the weekday is shown.

If FORMAT_SHOW_YEAR is set, then the year is always shown. If FORMAT_SHOW_YEAR is not set, then the year is shown only if it is different from the current year, or if the start and end dates fall on different years.

Normally the date is shown unless the start and end day are the same. If FORMAT_SHOW_DATE is set, then the date is always shown, even for same day ranges.

If FORMAT_NO_MONTH_DAY is set, then if the date is shown, just the month name will be shown, not the day of the month. For example, "January, 2008" instead of "January 6 - 12, 2008".

If FORMAT_CAP_AMPM is set and 12-hour time is used, then the "AM" and "PM" are capitalized. You should not use this flag because in some locales these terms cannot be capitalized, and in many others it doesn't make sense to do so even though it is possible.

If FORMAT_NO_NOON is set and 12-hour time is used, then "12pm" is shown instead of "noon".

If FORMAT_CAP_NOON is set and 12-hour time is used, then "Noon" is shown instead of "noon". You should probably not use this flag because in many locales it will not make sense to capitalize the term.

If FORMAT_NO_MIDNIGHT is set and 12-hour time is used, then "12am" is shown instead of "midnight".

If FORMAT_CAP_MIDNIGHT is set and 12-hour time is used, then "Midnight" is shown instead of "midnight". You should probably not use this flag because in many locales it will not make sense to capitalize the term.

If FORMAT_12HOUR is set and the time is shown, then the time is shown in the 12-hour time format. You should not normally set this. Instead, let the time format be chosen automatically according to the system settings. If both FORMAT_12HOUR and FORMAT_24HOUR are set, then FORMAT_24HOUR takes precedence.

If FORMAT_24HOUR is set and the time is shown, then the time is shown in the 24-hour time format. You should not normally set this. Instead, let the time format be chosen automatically according to the system settings. If both FORMAT_12HOUR and FORMAT_24HOUR are set, then FORMAT_24HOUR takes precedence.

If FORMAT_UTC is set, then the UTC time zone is used for the start and end milliseconds unless a time zone is specified. If a time zone is specified it will be used regardless of the FORMAT_UTC flag.

If FORMAT_ABBREV_TIME is set and 12-hour time format is used, then the start and end times (if shown) are abbreviated by not showing the minutes if they are zero. For example, instead of "3:00pm" the time would be abbreviated to "3pm".

If FORMAT_ABBREV_WEEKDAY is set, then the weekday (if shown) is abbreviated to a 3-letter string.

If FORMAT_ABBREV_MONTH is set, then the month (if shown) is abbreviated to a 3-letter string.

If FORMAT_ABBREV_ALL is set, then the weekday and the month (if shown) are abbreviated to 3-letter strings.

If FORMAT_NUMERIC_DATE is set, then the date is shown in numeric format instead of using the name of the month. For example, "12/31/2008" instead of "December 31, 2008".

If the end date ends at 12:00am at the beginning of a day, it is formatted as the end of the previous day in two scenarios:

- For single day events. This results in "8pm - midnight" instead of "Nov 10, 8pm - Nov 11, 12am".
- When the time is not displayed. This results in "Nov 10 - 11" for an event with a start date of Nov 10 and an end date of Nov 12 at 00:00.

<br />

<br />

| Parameters ||
|---|---|
| `context` | `Context`: the context is required only if the time is shown <br /> |
| `formatter` | `Formatter`: the Formatter used for formatting the date range. Note: be sure to call setLength(0) on StringBuilder passed to the Formatter constructor unless you want the results to accumulate. <br /> |
| `startMillis` | `long`: the start time in UTC milliseconds <br /> |
| `endMillis` | `long`: the end time in UTC milliseconds <br /> |
| `flags` | `int`: a bit mask of options <br /> |
| `timeZone` | `String`: the id of the time zone to compute the string in. Use null for local or if the FORMAT_UTC flag is being used. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/Formatter` | the formatter with the formatted date/time range appended to the string buffer. <br /> |

### formatDateRange

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

```
public static Formatter formatDateRange (Context context, 
                Formatter formatter, 
                long startMillis, 
                long endMillis, 
                int flags)
```

Formats a date or a time range according to the local conventions.

Note that this is a convenience method for formatting the date or time range in the local time zone. If you want to specify the time zone please use `https://developer.android.com/reference/android/text/format/DateUtils#formatDateRange(android.content.Context,%20java.util.Formatter,%20long,%20long,%20int,%20java.lang.String)`.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: the context is required only if the time is shown <br /> |
| `formatter` | `Formatter`: the Formatter used for formatting the date range. Note: be sure to call setLength(0) on StringBuilder passed to the Formatter constructor unless you want the results to accumulate. <br /> |
| `startMillis` | `long`: the start time in UTC milliseconds <br /> |
| `endMillis` | `long`: the end time in UTC milliseconds <br /> |
| `flags` | `int`: a bit mask of options See `https://developer.android.com/reference/android/text/format/DateUtils#formatDateRange(android.content.Context,%20java.util.Formatter,%20long,%20long,%20int,%20java.lang.String)` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/Formatter` | a string containing the formatted date/time range. <br /> |

### formatDateRange

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

```
public static String formatDateRange (Context context, 
                long startMillis, 
                long endMillis, 
                int flags)
```

Formats a date or a time range according to the local conventions.

Note that this is a convenience method. Using it involves creating an internal `https://developer.android.com/reference/java/util/Formatter` instance on-the-fly, which is somewhat costly in terms of memory and time. This is probably acceptable if you use the method only rarely, but if you rely on it for formatting a large number of dates, consider creating and reusing your own `https://developer.android.com/reference/java/util/Formatter` instance and use the version of `https://developer.android.com/reference/android/text/format/DateUtils#formatDateRange(android.content.Context,%20long,%20long,%20int)` that takes a `https://developer.android.com/reference/java/util/Formatter`.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: the context is required only if the time is shown <br /> |
| `startMillis` | `long`: the start time in UTC milliseconds <br /> |
| `endMillis` | `long`: the end time in UTC milliseconds <br /> |
| `flags` | `int`: a bit mask of options See `https://developer.android.com/reference/android/text/format/DateUtils#formatDateRange(android.content.Context,%20java.util.Formatter,%20long,%20long,%20int,%20java.lang.String)` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string containing the formatted date/time range. <br /> |

### formatDateTime

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

```
public static String formatDateTime (Context context, 
                long millis, 
                int flags)
```

Formats a date or a time according to the local conventions. There are lots of options that allow the caller to control, for example, if the time is shown, if the day of the week is shown, if the month name is abbreviated, if noon is shown instead of 12pm, and so on. For the complete list of options, see the documentation for `https://developer.android.com/reference/android/text/format/DateUtils#formatDateRange(android.content.Context,%20java.util.Formatter,%20long,%20long,%20int)`.

Example output strings (date formats in these examples are shown using the US date format convention but that may change depending on the local settings):

- 10:15am
- 3:00pm
- 3pm
- 3PM
- 08:00
- 17:00
- noon
- Noon
- midnight
- Midnight
- Oct 31
- Oct 31, 2007
- October 31, 2007
- 10am, Oct 31
- 17:00, Oct 31
- Wed
- Wednesday
- 10am, Wed, Oct 31
- Wed, Oct 31
- Wednesday, Oct 31
- Wed, Oct 31, 2007
- Wed, October 31
- 10/31/2007

<br />

<br />

| Parameters ||
|---|---|
| `context` | `Context`: the context is required only if the time is shown <br /> |
| `millis` | `long`: a point in time in UTC milliseconds <br /> |
| `flags` | `int`: a bit mask of formatting options <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string containing the formatted date/time. <br /> |

### formatElapsedTime

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

```
public static String formatElapsedTime (StringBuilder recycle, 
                long elapsedSeconds)
```

Formats an elapsed time in a format like "MM:SS" or "H:MM:SS" (using a form suited to the current locale), similar to that used on the call-in-progress screen.

<br />

| Parameters ||
|---|---|
| `recycle` | `StringBuilder`: `https://developer.android.com/reference/java/lang/StringBuilder` to recycle, or null to use a temporary one. <br /> |
| `elapsedSeconds` | `long`: the elapsed time in seconds. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |

### formatElapsedTime

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

```
public static String formatElapsedTime (long elapsedSeconds)
```

Formats an elapsed time in the form "MM:SS" or "H:MM:SS" for display on the call-in-progress screen.

<br />

| Parameters ||
|---|---|
| `elapsedSeconds` | `long`: the elapsed time in seconds. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |

### formatSameDayTime

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

```
public static final CharSequence formatSameDayTime (long then, 
                long now, 
                int dateStyle, 
                int timeStyle)
```

Format a date / time such that if the then is on the same day as now, it shows just the time and if it's a different day, it shows just the date.

The parameters dateFormat and timeFormat should each be one of `https://developer.android.com/reference/java/text/DateFormat#DEFAULT`, `https://developer.android.com/reference/java/text/DateFormat#FULL`, `https://developer.android.com/reference/java/text/DateFormat#LONG`, `https://developer.android.com/reference/java/text/DateFormat#MEDIUM` or `https://developer.android.com/reference/java/text/DateFormat#SHORT`

<br />

| Parameters ||
|---|---|
| `then` | `long`: the date to format <br /> |
| `now` | `long`: the base time <br /> |
| `dateStyle` | `int`: how to format the date portion. <br /> |
| `timeStyle` | `int`: how to format the time portion. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | <br /> |

### getAMPMString

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

```
public static String getAMPMString (int ampm)
```

<br />

**This method was deprecated in API level 17.**   

Use `https://developer.android.com/reference/java/text/SimpleDateFormat` instead.

Return a localized string for AM or PM.

<br />

| Parameters ||
|---|---|
| `ampm` | `int`: Either `https://developer.android.com/reference/java/util/Calendar#AM` or `https://developer.android.com/reference/java/util/Calendar#PM`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | Localized version of "AM" or "PM". <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | if the ampm is out of bounds. |

### getDayOfWeekString

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

```
public static String getDayOfWeekString (int dayOfWeek, 
                int abbrev)
```

<br />

**This method was deprecated in API level 17.**   

Use `https://developer.android.com/reference/java/text/SimpleDateFormat` instead.

Return a string for the day of the week.

<br />

| Parameters ||
|---|---|
| `dayOfWeek` | `int`: One of `https://developer.android.com/reference/java/util/Calendar#SUNDAY`, `https://developer.android.com/reference/java/util/Calendar#MONDAY`, etc. <br /> |
| `abbrev` | `int`: One of `https://developer.android.com/reference/android/text/format/DateUtils#LENGTH_LONG`, `https://developer.android.com/reference/android/text/format/DateUtils#LENGTH_SHORT`, `https://developer.android.com/reference/android/text/format/DateUtils#LENGTH_MEDIUM`, or `https://developer.android.com/reference/android/text/format/DateUtils#LENGTH_SHORTEST`. Note that in most languages, `https://developer.android.com/reference/android/text/format/DateUtils#LENGTH_SHORT` will return the same as `https://developer.android.com/reference/android/text/format/DateUtils#LENGTH_MEDIUM`. Undefined lengths will return `https://developer.android.com/reference/android/text/format/DateUtils#LENGTH_MEDIUM` but may return something different in the future. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IndexOutOfBoundsException` | if the dayOfWeek is out of bounds. |

### getMonthString

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

```
public static String getMonthString (int month, 
                int abbrev)
```

<br />

**This method was deprecated in API level 17.**   

Use `https://developer.android.com/reference/java/text/SimpleDateFormat` instead.

Return a localized string for the month of the year.

<br />

| Parameters ||
|---|---|
| `month` | `int`: One of `https://developer.android.com/reference/java/util/Calendar#JANUARY`, `https://developer.android.com/reference/java/util/Calendar#FEBRUARY`, etc. <br /> |
| `abbrev` | `int`: One of `https://developer.android.com/reference/android/text/format/DateUtils#LENGTH_LONG`, `https://developer.android.com/reference/android/text/format/DateUtils#LENGTH_MEDIUM`, or `https://developer.android.com/reference/android/text/format/DateUtils#LENGTH_SHORTEST`. Undefined lengths will return `https://developer.android.com/reference/android/text/format/DateUtils#LENGTH_MEDIUM` but may return something different in the future. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | Localized month of the year. <br /> |

### getRelativeDateTimeString

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

```
public static CharSequence getRelativeDateTimeString (Context c, 
                long time, 
                long minResolution, 
                long transitionResolution, 
                int flags)
```

Return string describing the elapsed time since startTime formatted like "\[relative time/date\], \[time\]".

Example output strings for the US date format.

- 3 min. ago, 10:15 AM
- Yesterday, 12:20 PM
- Dec 12, 4:12 AM
- 11/14/2007, 8:20 AM

<br />

<br />

| Parameters ||
|---|---|
| `c` | `Context` <br /> |
| `time` | `long`: some time in the past. <br /> |
| `minResolution` | `long`: the minimum elapsed time (in milliseconds) to report when showing relative times. For example, a time 3 seconds in the past will be reported as "0 minutes ago" if this is set to `https://developer.android.com/reference/android/text/format/DateUtils#MINUTE_IN_MILLIS`. <br /> |
| `transitionResolution` | `long`: the elapsed time (in milliseconds) at which to stop reporting relative measurements. Elapsed times greater than this resolution will default to normal date formatting. For example, will transition from "7 days ago" to "Dec 12" when using `https://developer.android.com/reference/android/text/format/DateUtils#WEEK_IN_MILLIS`. <br /> |
| `flags` | `int` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | <br /> |

### getRelativeTimeSpanString

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

```
public static CharSequence getRelativeTimeSpanString (Context c, 
                long millis, 
                boolean withPreposition)
```

<br />

<br />

| Parameters ||
|---|---|
| `c` | `Context` <br /> |
| `millis` | `long` <br /> |
| `withPreposition` | `boolean`: If true, the string returned will include the correct preposition ("at 9:20am", "on 10/12/2008" or "on May 29"). <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | a relative time string to display the time expressed by millis. Times are counted starting at midnight, which means that assuming that the current time is March 31st, 0:30: - "millis=0:10 today" will be displayed as "0:10" - "millis=11:30pm the day before" will be displayed as "Mar 30" If the given millis is in a different year, then the full date is returned in numeric format (e.g., "10/12/2008"). <br /> |

### getRelativeTimeSpanString

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

```
public static CharSequence getRelativeTimeSpanString (long time, 
                long now, 
                long minResolution, 
                int flags)
```

Returns a string describing 'time' as a time relative to 'now'.

Time spans in the past are formatted like "42 minutes ago". Time spans in the future are formatted like "In 42 minutes".

Can use `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_ABBREV_RELATIVE` flag to use abbreviated relative times, like "42 mins ago".

<br />

| Parameters ||
|---|---|
| `time` | `long`: the time to describe, in milliseconds <br /> |
| `now` | `long`: the current time in milliseconds <br /> |
| `minResolution` | `long`: the minimum timespan to report. For example, a time 3 seconds in the past will be reported as "0 minutes ago" if this is set to MINUTE_IN_MILLIS. Pass one of 0, MINUTE_IN_MILLIS, HOUR_IN_MILLIS, DAY_IN_MILLIS, WEEK_IN_MILLIS <br /> |
| `flags` | `int`: a bit mask of formatting options, such as `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_NUMERIC_DATE` or `https://developer.android.com/reference/android/text/format/DateUtils#FORMAT_ABBREV_RELATIVE` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | <br /> |

### getRelativeTimeSpanString

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

```
public static CharSequence getRelativeTimeSpanString (long startTime)
```

Returns a string describing the elapsed time since startTime.

The minimum timespan to report is set to `https://developer.android.com/reference/android/text/format/DateUtils#MINUTE_IN_MILLIS`.

<br />

| Parameters ||
|---|---|
| `startTime` | `long`: some time in the past. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | a String object containing the elapsed time. <br /> |

**See also:**

- `https://developer.android.com/reference/android/text/format/DateUtils#getRelativeTimeSpanString(long,%20long,%20long)`

### getRelativeTimeSpanString

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

```
public static CharSequence getRelativeTimeSpanString (Context c, 
                long millis)
```

Convenience function to return relative time string without preposition.

<br />

| Parameters ||
|---|---|
| `c` | `Context`: context for resources <br /> |
| `millis` | `long`: time in milliseconds <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | `https://developer.android.com/reference/java/lang/CharSequence` containing relative time. <br /> |

**See also:**

- `https://developer.android.com/reference/android/text/format/DateUtils#getRelativeTimeSpanString(android.content.Context,%20long,%20boolean)`

### getRelativeTimeSpanString

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

```
public static CharSequence getRelativeTimeSpanString (long time, 
                long now, 
                long minResolution)
```

Returns a string describing 'time' as a time relative to 'now'.

Time spans in the past are formatted like "42 minutes ago". Time spans in the future are formatted like "In 42 minutes".

<br />

| Parameters ||
|---|---|
| `time` | `long`: the time to describe, in milliseconds <br /> |
| `now` | `long`: the current time in milliseconds <br /> |
| `minResolution` | `long`: the minimum timespan to report. For example, a time 3 seconds in the past will be reported as "0 minutes ago" if this is set to MINUTE_IN_MILLIS. Pass one of 0, MINUTE_IN_MILLIS, HOUR_IN_MILLIS, DAY_IN_MILLIS, WEEK_IN_MILLIS <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | <br /> |

### isToday

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

```
public static boolean isToday (long when)
```

<br />

<br />

| Parameters ||
|---|---|
| `when` | `long` <br /> |

| Returns ||
|---|---|
| `boolean` | true if the supplied when is today else false <br /> |