Package 

Class DateUtils


  • 
    public class DateUtils
    
                        

    A 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.

    • Method Summary

      Modifier and Type Method Description
      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).
      static String formatDateTime(Context context, ReadableInstant time, int flags) Formats a date or a time according to the local conventions.
      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.
      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.
      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.
      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.
      static boolean isToday(ReadablePartial time) See isToday for full docs.
      static boolean isToday(ReadableInstant time) See isToday for full docs.
      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.
      static CharSequence getRelativeTimeSpanString(Context context, ReadableInstant time) Returns a string describing 'time' as a time relative to the current time.
      static CharSequence getRelativeTimeSpanString(Context context, ReadablePartial time, int flags) Returns a string describing 'time' as a time relative to the current time.
      static CharSequence getRelativeTimeSpanString(Context context, ReadableInstant time, int flags) Returns a string describing 'time' as a time relative to 'now'.
      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.
      static CharSequence getRelativeTimeSpanString(Context ctx, ReadableInstant time, boolean withPreposition) Returns a relative time string to display the time expressed by millis.
      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]".
      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]".
      static CharSequence formatDuration(Context context, ReadableDuration readableDuration) Return given duration in a human-friendly format.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 shown
        time - a point in time
        flags - 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 shown
        time - a point in time
        flags - 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 shown
        start - the start time
        end - the end time
        flags - 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 shown
        start - the start time
        end - the end time
        flags - 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
      • isToday

         static boolean isToday(ReadablePartial time)

        See isToday for full docs.

      • isToday

         static boolean isToday(ReadableInstant time)

        See isToday for full docs.

      • 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, int flags)

        Returns a string describing 'time' as a time relative to 'now'.See getRelativeTimeSpanString for full docs.

        Parameters:
        context - the context
        time - the time to describe
        flags - 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, 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 context
        time - some time
        transitionResolution - 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.