Flutter: Fixed formats for DateFormat

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 static methods like below. (Flutter uses the current locale by default)

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

 by the author.

--

--

--

Native mobile app developer (Android/Flutter/iOS)

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Optimizing your BigQuery tables using partitioning: Time-unit column-partitioned tables

Management Area 3: Operations

Designing the Rust Unleash API client

Fooling Windows about its internal CPU

Controlling Animation through Code

SQL Part 8

Why Reinvent Deduplication? Isn’t Cloud Storage Cheap?

Flutter Context and “.of” method

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Gerrel

Gerrel

Native mobile app developer (Android/Flutter/iOS)

More from Medium

Divider in Flutter

Custom Option Selection Widget — Flutter.

A Peep into the Benefits of Flutter

What Are the Main Advantages of Flutter? Why Should You Choose Flutter in 2022?