b2cloud

24th October 2012

Relative time formatting

Thoughts By 5 years ago

Recently I was given the requirement of displaying relative time in certain areas of the app. Relative time formatting is displaying the time since something occurred relative to the current time i.e. the event occurred 5 minutes ago. As soon as I was given the requirements the builder part of my brain kicked in and before I knew it I was piecing together all the bits and pieces of code in my head, when an obvious thought struck me. Surely this type of request isn’t out of the ordinary, more to the point surely there had to be a library already written to handle it. A short time after that thought Google led me straight to the perfect library.

That perfect library which saved a whole lot development time (may be an exaggeration) is called Pretty Time and can be found here. What makes Pretty Time so useful is that it’s so simple to use. Customisation is as simple as extending the current TimeUnit with the text you want to display. The best part about all of this is that the library has automatic locale support built right in so there’s no worrying about string resources holding different languages. The library itself is very small and  efficient. I was able to use it for formatting inside a Android ListAdapter with no noticeable performance issues to the ListView itself even on an old Motorola Milestone.

So if you need relative time formatting in an Android or Java app I’d definitely recommend checking it out.

Recommended Posts

Write JNI wrappers for Android

Post by 5 years ago

Following are the steps that you need to follow in order to make things working – 1. Setting up the NDK on my machine 2. Learn how to write JNI wrappers 3. Learn C++ briefly so

Connect With Us

We're trusted by some of the largest businesses and enterprises to build digital products that matter.