Posts

Showing posts from May, 2014

Date & Joda DateTime

Image
Its always been a challenge for me when it comes to "Dates" be it java or real life. I had a task to make all the dates in my project UTC dates. For newbeeis "UTC" date means the date should reflect date that would reflect the time at GMT at any given time. Which means you need to +/- the hours based on the offset from the GMT. A quick and easy way to do this is using Joda DateTime. I used it and here is a sample code to illustrate how it can be implemented: Its also possible to convert a local time to another timezone using this feature. For example from IST to EST using the same code  by adjusting the timezone constant. However the challenge i faced was, I realized that my database (Oracle) used datatype "date" which has seamless integration with java.lang.Date. Converting a joda DateTime with timezone offset to java Date is a bit tricky. I found a DateFormat that suited my case: "yyyy-MM-dd'T'HH:mm:ss.SSSXXX". Unfortunately...