Skip to content
 

Android date / calendar persistence

A lesson from my voyage into the world of Android app development: java.util.Calendar and the SQLite database timestamp datatype do not mix!

If having problems using the Calendar class(es) I would thoroughly recommend you instead instantiate a java.sql.timestamp and persist that to the database instead. This cost me rather a lot of time debugging an error for which I was quite sure the application logic was at fault. In fact Calendar.setTimeInMillis() and Calendar.getTimeInMillis() is rather unpredictable when one tries to persist and retrieve a date-time, particularly in the world of Android. The name of Timestamp is a clue and I should have thought of using the corresponding class to represent the date-time in my application… oh well lesson learnt!

Leave a Reply