-
public class DateUtilsA replacement for android.text.format.DateUtils that uses Joda-Time classes. It is not a 1:1 implementation of Android's DateUtils. There are a few improvements made: - Deprecated constants have been removed. - Constants which are better represented by Joda-Time classes have been removed. - minResolution has been removed from relative time span methods because they make no sense. All it does is remove meaningful information from the string. E.g., it turns "in 30 seconds" into "in 0 minutes", or "in 5 hours" into "in 0 days". Having 0 of anything doesn't tell the user anything and should not be encouraged. - "now" has been removed from methods as a parameter. There is (AFAIK) no reason to use any time but the current time for now, especially when formatting date/times in relation to now.
-
-
Field Summary
Fields Modifier and Type Field Description public final static intFORMAT_SHOW_TIMEpublic final static intFORMAT_SHOW_WEEKDAYpublic final static intFORMAT_SHOW_YEARpublic final static intFORMAT_NO_YEARpublic final static intFORMAT_SHOW_DATEpublic final static intFORMAT_NO_MONTH_DAYpublic final static intFORMAT_NO_NOONpublic final static intFORMAT_NO_MIDNIGHTpublic final static intFORMAT_ABBREV_TIMEpublic final static intFORMAT_ABBREV_WEEKDAYpublic final static intFORMAT_ABBREV_MONTHpublic final static intFORMAT_NUMERIC_DATEpublic final static intFORMAT_ABBREV_RELATIVEpublic final static intFORMAT_ABBREV_ALL
-
Method Summary
Modifier and Type Method Description static StringformatDateTime(Context context, ReadablePartial time, int flags)Formats a date or a time according to the local conventions.Since ReadablePartials don't support all fields, we fill in any blanksneeded for formatting by using the epoch (1970-01-01T00:00:00Z). static StringformatDateTime(Context context, ReadableInstant time, int flags)Formats a date or a time according to the local conventions. static StringformatDateRange(Context context, ReadablePartial start, ReadablePartial end, int flags)Formats a date or a time range according to the local conventions.You should ensure that start/end are in the same timezone; formatDateRange()doesn't handle start/end in different timezones well. static StringformatDateRange(Context context, ReadableInstant start, ReadableInstant end, int flags)Formats a date or a time range according to the local conventions.You should ensure that start/end are in the same timezone; formatDateRange()doesn't handle start/end in different timezones well. static StringformatElapsedTime(ReadableDuration elapsedDuration)Formats an elapsed time in the form "MM:SS" or "H:MM:SS"for display on the call-in-progress screen. static StringformatElapsedTime(StringBuilder recycle, ReadableDuration elapsedDuration)Formats an elapsed time in a format like "MM:SS" or "H:MM:SS" (using a formsuited to the current locale), similar to that used on the call-in-progressscreen. static booleanisToday(ReadablePartial time)See isToday for full docs. static booleanisToday(ReadableInstant time)See isToday for full docs. static CharSequencegetRelativeTimeSpanString(Context context, ReadablePartial time)Returns a string describing 'time' as a time relative to the current time.Missing fields from 'time' are filled in with values from the current time. static CharSequencegetRelativeTimeSpanString(Context context, ReadableInstant time)Returns a string describing 'time' as a time relative to the current time. static CharSequencegetRelativeTimeSpanString(Context context, ReadablePartial time, int flags)Returns a string describing 'time' as a time relative to the current time. static CharSequencegetRelativeTimeSpanString(Context context, ReadableInstant time, int flags)Returns a string describing 'time' as a time relative to 'now'. static CharSequencegetRelativeTimeSpanString(Context ctx, ReadablePartial time, boolean withPreposition)Returns a relative time string to display the time expressed by millis.Missing fields from 'time' are filled in with values from the current time. static CharSequencegetRelativeTimeSpanString(Context ctx, ReadableInstant time, boolean withPreposition)Returns a relative time string to display the time expressed by millis. static CharSequencegetRelativeDateTimeString(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 CharSequencegetRelativeDateTimeString(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 CharSequenceformatDuration(Context context, ReadableDuration readableDuration)Return given duration in a human-friendly format. -
-
Method Detail
-
formatDateTime
static String formatDateTime(Context context, ReadablePartial time, int flags)
Formats a date or a time according to the local conventions.Since ReadablePartials don't support all fields, we fill in any blanksneeded for formatting by using the epoch (1970-01-01T00:00:00Z).See formatDateTime for full docs.
- Parameters:
context- the context is required only if the time is showntime- a point in timeflags- a bit mask of formatting options
-
formatDateTime
static String formatDateTime(Context context, ReadableInstant time, int flags)
Formats a date or a time according to the local conventions.See formatDateTime for full docs.
- Parameters:
context- the context is required only if the time is showntime- a point in timeflags- a bit mask of formatting options
-
formatDateRange
static String formatDateRange(Context context, ReadablePartial start, ReadablePartial end, int flags)
Formats a date or a time range according to the local conventions.You should ensure that start/end are in the same timezone; formatDateRange()doesn't handle start/end in different timezones well.See formatDateRange for full docs.
- Parameters:
context- the context is required only if the time is shownstart- the start timeend- the end timeflags- a bit mask of options
-
formatDateRange
static String formatDateRange(Context context, ReadableInstant start, ReadableInstant end, int flags)
Formats a date or a time range according to the local conventions.You should ensure that start/end are in the same timezone; formatDateRange()doesn't handle start/end in different timezones well.See formatDateRange for full docs.
- Parameters:
context- the context is required only if the time is shownstart- the start timeend- the end timeflags- a bit mask of options
-
formatElapsedTime
static 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.See formatElapsedTime for full docs.
- Parameters:
elapsedDuration- the elapsed duration
-
formatElapsedTime
static String formatElapsedTime(StringBuilder recycle, ReadableDuration elapsedDuration)
Formats an elapsed time in a format like "MM:SS" or "H:MM:SS" (using a formsuited to the current locale), similar to that used on the call-in-progressscreen.See formatElapsedTime for full docs.
- Parameters:
recycle- StringBuilder to recycle, or null to use a temporary one.elapsedDuration- the elapsed duration
-
getRelativeTimeSpanString
static CharSequence getRelativeTimeSpanString(Context context, ReadablePartial time)
Returns a string describing 'time' as a time relative to the current time.Missing fields from 'time' are filled in with values from the current time.
-
getRelativeTimeSpanString
static CharSequence getRelativeTimeSpanString(Context context, ReadableInstant time)
Returns a string describing 'time' as a time relative to the current time.
-
getRelativeTimeSpanString
static CharSequence getRelativeTimeSpanString(Context context, ReadablePartial time, int flags)
Returns a string describing 'time' as a time relative to the current time.
-
getRelativeTimeSpanString
static CharSequence getRelativeTimeSpanString(Context context, ReadableInstant time, int flags)
Returns a string describing 'time' as a time relative to 'now'.See getRelativeTimeSpanString for full docs.
- Parameters:
context- the contexttime- the time to describeflags- a bit mask for formatting options, usually FORMAT_ABBREV_RELATIVE
-
getRelativeTimeSpanString
static CharSequence getRelativeTimeSpanString(Context ctx, ReadablePartial time, boolean withPreposition)
Returns a relative time string to display the time expressed by millis.Missing fields from 'time' are filled in with values from the current time.See getRelativeTimeSpanString for full docs.
- Parameters:
withPreposition- If true, the string returned will include the correctpreposition ("at 9:20am", "on 10/12/2008" or "on May 29").
-
getRelativeTimeSpanString
static CharSequence getRelativeTimeSpanString(Context ctx, ReadableInstant time, boolean withPreposition)
Returns a relative time string to display the time expressed by millis.See getRelativeTimeSpanString for full docs.
- Parameters:
withPreposition- If true, the string returned will include the correctpreposition ("at 9:20am", "on 10/12/2008" or "on May 29").
-
getRelativeDateTimeString
static CharSequence getRelativeDateTimeString(Context context, ReadablePartial time, ReadablePeriod transitionResolution, int flags)
Return string describing the time until/elapsed time since 'time' formatted like"[relative time/date], [time]".See getRelativeDateTimeString for full docs.
-
getRelativeDateTimeString
static CharSequence getRelativeDateTimeString(Context context, ReadableInstant time, ReadablePeriod transitionResolution, int flags)
Return string describing the time until/elapsed time since 'time' formatted like"[relative time/date], [time]".See getRelativeDateTimeString for full docs.
- Parameters:
context- the contexttime- some timetransitionResolution- the elapsed time (period) at whichto stop reporting relative measurements.flags- flags for getRelativeTimeSpanString() (if duration is less than transitionResolution)
-
formatDuration
static CharSequence formatDuration(Context context, ReadableDuration readableDuration)
Return given duration in a human-friendly format. For example, "4minutes" or "1 second". Returns only largest meaningful unit of time,from seconds up to hours.The longest duration it supports is hours.This method assumes that there are 60 minutes in an hour,60 seconds in a minute and 1000 milliseconds in a second.All currently supplied chronologies use this definition.
-
-
-
-