Press "Enter" to skip to content

Relative time formatting in Xamarin Forms

A good UX practice is to use a relative time formatting instead of showing dates using normal date formats. It helps the user to have a quick sense of the timeframe without having to calculate exactly when it happened, also provides a better look and feel to your app.

You can see this commonly used in applications like Facebook, Instagram, Gmail, etc. Because is easier to read “2 minutes ago” than “9:23 2/3/18”.

One great way to do this in Xamarin Forms is by using converters. In the following steps will show you how to get all set with relative time formatting:

Create your converter

Add the converter to your page

Use the converter

You can find the full source code of this sample here:

https://github.com/CrossGeeks/RelativeTimeSample

References:

https://stackoverflow.com/questions/11/calculate-relative-time-in-c-sharp
http://uxmovement.com/content/absolute-vs-relative-timestamps-when-to-use-which/

Happy date formatting!

One Comment

  1. Nikolaj Hesselholt Skov Nikolaj Hesselholt Skov

    Hi!

    I totally agree with you on using relative time instead of exact time stamps, but have you heard of Humanizer? It does the same and many other things in that area.

    Link: https://github.com/Humanizr/Humanizer

    /Nikolaj

Comments are closed.