I’m new to android. I have a table in database which has date column as String type and stores the date in this format “dmyyyy” I need to retrieve date present in this format from sqlite database and update that value to DatePicker view. How do i achieve this, please help me.
e.g: “1102012” (1-Nov-2012)
thanks in advance.
Firstly, why are you storing them as strings in that format in the first place? You’ve got a thoroughly ambiguous format – assuming you just made a mistake in your example, how would you tell the difference between “January 11th” and “November 1st”? Both would be “111” followed by the year.
As I understand it, SQLite usually uses ISO-8601 representations of dates and times – that’s what its date/time functions use, and that’s what I’d expect client libraries to expose.
Anyway, when it comes to parsing, you could either use Joda Time which is a third-party date/time API and much better than the built-in
DateandCalendarclasses, or you could useSimpleDateFormat. I suggest you explicitly specify theLocale(ideally something likeLocale.US, not the user’s locale – this is just for storage) the time zone (again, you should almost certainly use UTC rather than the user’s time zone) and the pattern (e.g.yyyy-MM-ddfor ISO-8601). Then useparseto retrieve aDate… which you’ll probably want to then set into aCalendarwith the same time zone, in order to get at more useful information.