Archive for April, 2011

I’ve been a heavy user of simpleDB  from past couple of months, here’s my advise to people working with date in simpleDB ::

As we all know that everything in simpleDB is a String, hence ALWAYS use a single time zone while storing dates, otherwise results might be error prone  as sorting is lexicographical. I’ll recommend Joda-Time(ISO8601 format) to store dates as it provides a quality replacement for the Java date and time classes with simple API. Preferably use Zulu time zone (i.e. GMT)

Here’s how to do it ::

DateTime date = new DateTime(DateTimeZone.forID("Etc/Zulu"));

While using date in your application return time in milliseconds as it is easier to use.The code below expresses the datetime as milliseconds from 1970-01-01T00:00:00Z

String time = message.getDate();
DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
DateTime dt = fmt.parseDateTime(time);
time = Long.toString(dt.getMillis());