public class DateUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
FORMAT_ABBREV_ALL |
static int |
FORMAT_ABBREV_MONTH |
static int |
FORMAT_ABBREV_RELATIVE |
static int |
FORMAT_ABBREV_TIME |
static int |
FORMAT_ABBREV_WEEKDAY |
static int |
FORMAT_NO_MIDNIGHT |
static int |
FORMAT_NO_MONTH_DAY |
static int |
FORMAT_NO_NOON |
static int |
FORMAT_NO_YEAR |
static int |
FORMAT_NUMERIC_DATE |
static int |
FORMAT_SHOW_DATE |
static int |
FORMAT_SHOW_TIME |
static int |
FORMAT_SHOW_WEEKDAY |
static int |
FORMAT_SHOW_YEAR |
Constructor and Description |
---|
DateUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
formatDateRange(android.content.Context context,
ReadableInstant start,
ReadableInstant end,
int flags)
Formats a date or a time range according to the local conventions.
|
static java.lang.String |
formatDateRange(android.content.Context context,
ReadablePartial start,
ReadablePartial end,
int flags)
Formats a date or a time range according to the local conventions.
|
static java.lang.String |
formatDateTime(android.content.Context context,
ReadableInstant time,
int flags)
Formats a date or a time according to the local conventions.
|
static java.lang.String |
formatDateTime(android.content.Context context,
ReadablePartial time,
int flags)
Formats a date or a time according to the local conventions.
|
static java.lang.CharSequence |
formatDuration(android.content.Context context,
ReadableDuration readableDuration)
Return given duration in a human-friendly format.
|
static java.lang.String |
formatElapsedTime(ReadableDuration elapsedDuration)
Formats an elapsed time in the form "MM:SS" or "H:MM:SS"
for display on the call-in-progress screen.
|
static java.lang.String |
formatElapsedTime(java.lang.StringBuilder recycle,
ReadableDuration elapsedDuration)
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 java.lang.CharSequence |
getRelativeDateTimeString(android.content.Context context,
ReadableInstant time,
ReadablePeriod transitionResolution,
int flags)
Return string describing the time until/elapsed time since 'time' formatted like
"[relative time/date], [time]".
|
static java.lang.CharSequence |
getRelativeDateTimeString(android.content.Context context,
ReadablePartial time,
ReadablePeriod transitionResolution,
int flags)
Return string describing the time until/elapsed time since 'time' formatted like
"[relative time/date], [time]".
|
static java.lang.CharSequence |
getRelativeTimeSpanString(android.content.Context context,
ReadableInstant time)
Returns a string describing 'time' as a time relative to the current time.
|
static java.lang.CharSequence |
getRelativeTimeSpanString(android.content.Context ctx,
ReadableInstant time,
boolean withPreposition)
Returns a relative time string to display the time expressed by millis.
|
static java.lang.CharSequence |
getRelativeTimeSpanString(android.content.Context context,
ReadableInstant time,
int flags)
Returns a string describing 'time' as a time relative to 'now'.
|
static java.lang.CharSequence |
getRelativeTimeSpanString(android.content.Context context,
ReadablePartial time)
Returns a string describing 'time' as a time relative to the current time.
|
static java.lang.CharSequence |
getRelativeTimeSpanString(android.content.Context ctx,
ReadablePartial time,
boolean withPreposition)
Returns a relative time string to display the time expressed by millis.
|
static java.lang.CharSequence |
getRelativeTimeSpanString(android.content.Context context,
ReadablePartial time,
int flags)
Returns a string describing 'time' as a time relative to the current time.
|
static boolean |
isToday(ReadableInstant time)
See
DateUtils.isToday(long) for full docs. |
static boolean |
isToday(ReadablePartial time)
See
DateUtils.isToday(long) for full docs. |
public static final int FORMAT_SHOW_TIME
public static final int FORMAT_SHOW_WEEKDAY
public static final int FORMAT_SHOW_YEAR
public static final int FORMAT_NO_YEAR
public static final int FORMAT_SHOW_DATE
public static final int FORMAT_NO_MONTH_DAY
public static final int FORMAT_NO_NOON
public static final int FORMAT_NO_MIDNIGHT
public static final int FORMAT_ABBREV_TIME
public static final int FORMAT_ABBREV_WEEKDAY
public static final int FORMAT_ABBREV_MONTH
public static final int FORMAT_NUMERIC_DATE
public static final int FORMAT_ABBREV_RELATIVE
public static final int FORMAT_ABBREV_ALL
public static java.lang.String formatDateTime(android.content.Context context, ReadablePartial time, int flags)
DateUtils.formatDateTime(android.content.Context, long, int)
for full docs.context
- the context is required only if the time is showntime
- a point in timeflags
- a bit mask of formatting optionspublic static java.lang.String formatDateTime(android.content.Context context, ReadableInstant time, int flags)
DateUtils.formatDateTime(android.content.Context, long, int)
for full docs.context
- the context is required only if the time is showntime
- a point in timeflags
- a bit mask of formatting optionspublic static java.lang.String formatDateRange(android.content.Context context, ReadablePartial start, ReadablePartial end, int flags)
DateUtils.formatDateRange(android.content.Context, long, long, int)
for full docs.context
- the context is required only if the time is shownstart
- the start timeend
- the end timeflags
- a bit mask of optionspublic static java.lang.String formatDateRange(android.content.Context context, ReadableInstant start, ReadableInstant end, int flags)
DateUtils.formatDateRange(android.content.Context, long, long, int)
for full docs.context
- the context is required only if the time is shownstart
- the start timeend
- the end timeflags
- a bit mask of optionspublic static java.lang.String formatElapsedTime(ReadableDuration elapsedDuration)
DateUtils.formatElapsedTime(long)
for full docs.elapsedDuration
- the elapsed durationpublic static java.lang.String formatElapsedTime(java.lang.StringBuilder recycle, ReadableDuration elapsedDuration)
DateUtils.formatElapsedTime(long)
for full docs.recycle
- StringBuilder
to recycle, or null to use a temporary one.elapsedDuration
- the elapsed durationpublic static boolean isToday(ReadablePartial time)
DateUtils.isToday(long)
for full docs.public static boolean isToday(ReadableInstant time)
DateUtils.isToday(long)
for full docs.public static java.lang.CharSequence getRelativeTimeSpanString(android.content.Context context, ReadablePartial time)
public static java.lang.CharSequence getRelativeTimeSpanString(android.content.Context context, ReadableInstant time)
public static java.lang.CharSequence getRelativeTimeSpanString(android.content.Context context, ReadablePartial time, int flags)
public static java.lang.CharSequence getRelativeTimeSpanString(android.content.Context context, ReadableInstant time, int flags)
DateUtils.getRelativeTimeSpanString(long)
for full docs.context
- the contexttime
- the time to describeflags
- a bit mask for formatting options, usually FORMAT_ABBREV_RELATIVEpublic static java.lang.CharSequence getRelativeTimeSpanString(android.content.Context ctx, ReadablePartial time, boolean withPreposition)
DateUtils.getRelativeTimeSpanString(long)
for full docs.withPreposition
- If true, the string returned will include the correct
preposition ("at 9:20am", "on 10/12/2008" or "on May 29").public static java.lang.CharSequence getRelativeTimeSpanString(android.content.Context ctx, ReadableInstant time, boolean withPreposition)
DateUtils.getRelativeTimeSpanString(long)
for full docs.withPreposition
- If true, the string returned will include the correct
preposition ("at 9:20am", "on 10/12/2008" or "on May 29").public static java.lang.CharSequence getRelativeDateTimeString(android.content.Context context, ReadablePartial time, ReadablePeriod transitionResolution, int flags)
DateUtils.getRelativeDateTimeString(android.content.Context, long, long, long, int)
for full docs.java.lang.IllegalArgumentException
- if using a ReadablePartial without a time componentgetRelativeDateTimeString(Context, ReadableInstant, ReadablePeriod, int)
public static java.lang.CharSequence getRelativeDateTimeString(android.content.Context context, ReadableInstant time, ReadablePeriod transitionResolution, int flags)
DateUtils.getRelativeDateTimeString(android.content.Context, long, long, long, int)
for full docs.context
- the contexttime
- some timetransitionResolution
- the elapsed time (period) at which
to stop reporting relative measurements. Periods greater
than this resolution will default to normal date formatting.
For example, will transition from "6 days ago" to "Dec 12"
when using Weeks.ONE. If null, defaults to Days.ONE.
Clamps to min value of Days.ONE, max of Weeks.ONE.flags
- flags for getRelativeTimeSpanString() (if duration is less than transitionResolution)public static java.lang.CharSequence formatDuration(android.content.Context context, ReadableDuration readableDuration)