Folder icon

Tags / dates

Using one DateFormat instance per thread with ThreadLocal

Here is a quick tip how to use DateFormat inside a ThreadLocal field. Why do we need that? The reason is the DateFormat class is not thread-safe but creating its instances is an expensive operation. So, this is kind of a workaround that creates only one instance of DateFormat per thread.
Posted on

Parsing a date string to ISO8601 with Joda Time


Uncaught exception: the image was stolen by a UFO

Recently, I faced a date conversion task: convert a string date "yyyy-MM-ddZ" (i.e. "1983-09-15+03:00") to the ISO8601 standard "yyyy-MM-dd'T'HH:mm:ss.SSSZ" (i.e. "1983-09-15T03:00:00.000+03:00"). I used Apache Joda time to convert date. First, add a Maven dependency in pom.xml To format a string containing date, I…
Posted on