Format date and time in java with prettytime

Posted by Jens J├Ąger on November 14, 2015

Prettytime is a nice java library to format a java Date()s in a nice humanized ago format, like:

  • moments ago
  • 2 minutes ago
  • 13 hours ago
  • 7 months ago
  • 2 years ago

Prettytime is localized in over 30 languages.

It’s super simple to use

Add the dependency to your maven pom:

or an sbt dependency if you use an activator project like play framework.

Then add the following static method to a helper class and call it from your json processor or your template engine.

Thats it!

You can find the code on github and the documentation on the ocpsoft page. Happy coding.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

Comments