Android: Fixed formats for DateFormat

Gerrel
Nov 3, 2019

Obvious for some, but when you have users in different countries over the world using your mobile app. There isn’t a universal date format you can use. Users expect a date format that they use on a daily basis. The date format should be handled by the locale of the user configured on their phone.

Using a fixed format (like: yyyy-MM-dd’T’HH:mm:ss) for parsing the date that you receive from a server is ok. But if you need to present it to the user you should always use the style properties like below.

In my apps I define a date formatter as static val so that I can use it anywhere in the code.

--

--

Gerrel
Gerrel

Written by Gerrel

Native mobile app developer (Android/Flutter/iOS)

No responses yet