Skip to content

Formatting a recurrence

maltaisn edited this page Oct 19, 2019 · 2 revisions

To convert a recurrence object to a readable and localized string, you can create a RecurrenceFormat object. The class has a single method, format. The start date parameter is optional. Specifying the start date will include less details in the recurrence. For example, a weekly recurrence happening on Tue will be formatted to "Every week on Tue" without a start date and to "Every week" if start date is on Tuesday.

val formatter = RecurrenceFormater(DateFormat.getInstance())
val r = Recurrence(Period.MONTHLY)
println(formatter.format(context, r, startDate))

Recurrence.toString() will also produce a readable string in debug mode, but not localized.

Clone this wiki locally