Android: Fixed formats for DateFormat

Gerrel
Gerrel
Nov 3 · 1 min read

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.

It also works with great when using Jotive’s builder pattern for localized strings.

Gerrel

Written by

Gerrel

Native mobile app developer (Android/Flutter/iOS)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade