DateUtils.FormatDateRange Method

Definition

Overloads

FormatDateRange(Context, Int64, Int64, FormatStyleFlags)

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

FormatDateRange(Context, Formatter, Int64, Int64, FormatStyleFlags)

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

FormatDateRange(Context, Formatter, Int64, Int64, FormatStyleFlags, String)

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

FormatDateRange(Context, Int64, Int64, FormatStyleFlags)

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

[Android.Runtime.Register("formatDateRange", "(Landroid/content/Context;JJI)Ljava/lang/String;", "")]
public static string? FormatDateRange (Android.Content.Context? context, long startMillis, long endMillis, Android.Text.Format.FormatStyleFlags flags);
[<Android.Runtime.Register("formatDateRange", "(Landroid/content/Context;JJI)Ljava/lang/String;", "")>]
static member FormatDateRange : Android.Content.Context * int64 * int64 * Android.Text.Format.FormatStyleFlags -> string

Parameters

context
Context

the context is required only if the time is shown

startMillis
Int64

the start time in UTC milliseconds

endMillis
Int64

the end time in UTC milliseconds

flags
FormatStyleFlags

a bit mask of options See #formatDateRange(Context, Formatter, long, long, int, String) formatDateRange

Returns

a string containing the formatted date/time range.

Attributes

Remarks

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 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 java.util.Formatter instance and use the version of #formatDateRange(Context, long, long, int) formatDateRange that takes a java.util.Formatter.

Java documentation for android.text.format.DateUtils.formatDateRange(android.content.Context, long, long, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

FormatDateRange(Context, Formatter, Int64, Int64, FormatStyleFlags)

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

[Android.Runtime.Register("formatDateRange", "(Landroid/content/Context;Ljava/util/Formatter;JJI)Ljava/util/Formatter;", "")]
public static Java.Util.Formatter? FormatDateRange (Android.Content.Context? context, Java.Util.Formatter? formatter, long startMillis, long endMillis, Android.Text.Format.FormatStyleFlags flags);
[<Android.Runtime.Register("formatDateRange", "(Landroid/content/Context;Ljava/util/Formatter;JJI)Ljava/util/Formatter;", "")>]
static member FormatDateRange : Android.Content.Context * Java.Util.Formatter * int64 * int64 * Android.Text.Format.FormatStyleFlags -> Java.Util.Formatter

Parameters

context
Context

the context is required only if the time is shown

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.

startMillis
Int64

the start time in UTC milliseconds

endMillis
Int64

the end time in UTC milliseconds

flags
FormatStyleFlags

a bit mask of options See #formatDateRange(Context, Formatter, long, long, int, String) formatDateRange

Returns

a string containing the formatted date/time range.

Attributes

Remarks

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 #formatDateRange(Context, Formatter, long, long, int, String) formatDateRange.

Java documentation for android.text.format.DateUtils.formatDateRange(android.content.Context, java.util.Formatter, long, long, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

FormatDateRange(Context, Formatter, Int64, Int64, FormatStyleFlags, String)

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

[Android.Runtime.Register("formatDateRange", "(Landroid/content/Context;Ljava/util/Formatter;JJILjava/lang/String;)Ljava/util/Formatter;", "")]
public static Java.Util.Formatter? FormatDateRange (Android.Content.Context? context, Java.Util.Formatter? formatter, long startMillis, long endMillis, Android.Text.Format.FormatStyleFlags flags, string? timeZone);
[<Android.Runtime.Register("formatDateRange", "(Landroid/content/Context;Ljava/util/Formatter;JJILjava/lang/String;)Ljava/util/Formatter;", "")>]
static member FormatDateRange : Android.Content.Context * Java.Util.Formatter * int64 * int64 * Android.Text.Format.FormatStyleFlags * string -> Java.Util.Formatter

Parameters

context
Context

the context is required only if the time is shown

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.

startMillis
Int64

the start time in UTC milliseconds

endMillis
Int64

the end time in UTC milliseconds

flags
FormatStyleFlags

a bit mask of options

timeZone
String

the time zone to compute the string in. Use null for local or if the FORMAT_UTC flag is being used.

Returns

the formatter with the formatted date/time range appended to the string buffer.

Attributes

Remarks

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): <ul> <li>10:15am</li> <li>3:00pm - 4:00pm</li> <li>3pm - 4pm</li> <li>3PM - 4PM</li> <li>08:00 - 17:00</li> <li>Oct 9</li> <li>Tue, Oct 9</li> <li>October 9, 2007</li> <li>Oct 9 - 10</li> <li>Oct 9 - 10, 2007</li> <li>Oct 28 - Nov 3, 2007</li> <li>Dec 31, 2007 - Jan 1, 2008</li> <li>Oct 9, 8:00am - Oct 10, 5:00pm</li> <li>12/31/2007 - 01/01/2008</li> </ul>

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

<ul> <li>FORMAT_SHOW_TIME</li> <li>FORMAT_SHOW_WEEKDAY</li> <li>FORMAT_SHOW_YEAR</li> <li>FORMAT_SHOW_DATE</li> <li>FORMAT_NO_MONTH_DAY</li> <li>FORMAT_12HOUR</li> <li>FORMAT_24HOUR</li> <li>FORMAT_CAP_AMPM</li> <li>FORMAT_NO_NOON</li> <li>FORMAT_CAP_NOON</li> <li>FORMAT_NO_MIDNIGHT</li> <li>FORMAT_CAP_MIDNIGHT</li> <li>FORMAT_UTC</li> <li>FORMAT_ABBREV_TIME</li> <li>FORMAT_ABBREV_WEEKDAY</li> <li>FORMAT_ABBREV_MONTH</li> <li>FORMAT_ABBREV_ALL</li> <li>FORMAT_NUMERIC_DATE</li> </ul>

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: <ul> <li>For single day events. This results in "8pm - midnight" instead of "Nov 10, 8pm - Nov 11, 12am".</li> <li>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.</li> </ul>

Java documentation for android.text.format.DateUtils.formatDateRange(android.content.Context, java.util.Formatter, long, long, int, java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to