Android Format Date Range

Oct 4, 2019
val posted = LocalDateTime.now()val postedEnd = posted.plusDays(10)// 4 - 14 Octoberval text = DateUtils.formatDateRange(context, posted.toMillis()!!, postedEnd.toMillis()!!,  DateUtils.FORMAT_ABBREV_MONTH)

NOTE: Refer LocalDateTime.toMillis

fun formatDate(context: Context, posted: LocalDateTime, postedEnd: LocalDateTime? = null, flags: Int = DateUtils.FORMAT_ABBREV_MONTH): String? {    return if (postedEnd == null)        DateUtils.formatDateTime(context, posted.toMillis()!!, flags)    else        DateUtils.formatDateRange(context, posted.toMillis()!!, postedEnd.toMillis()!!, flags)}

References:

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.