

In this post I will present two alternatives:

Let’s go straight to the point and dive into the code instead. I won’t go into detail about KMM in this post. Luckily for us, we can utilize Kotlin Multiplatform Mobile (KMM) which enables us to write the same code once and use it across multiple platforms. But you have to write the “same” formatting logic twice if you write code for Android and iOS, for example, in two separate code bases. Should be easy enough to do on multiple platforms, right? Sure. Personally, every time I have to convert a date to a certain format, I think to myself - now again? Didn’t we do this before? There should be a way of writing this sort of code once and not having to bother with it again.Ī simple example of a date formatting requirement could be that we must display the text if (you guessed it) the current date is June 18th, 2022. Formatting dates often feels borderline tiresome to implement.
