java - Android error when convert month name -
with query select month in database. cursor returns exact month, when conversion display total name appears next month. example, cursor returns 6, instead method returns getdisplayname july.
sqlitedatabase db = new databasehelper(getactivity()).getreadabledatabase(); string sql = "select distinct strftime('%m',"+table.data+") "+table.table_name; cursor c = db.rawquery(sql, null); while (c.movetonext()){ int monthnumero = (c.getint(0)); calendar ca = calendar.getinstance(); ca.set(calendar.month, monthnumero); string monthname = ca.getdisplayname (calendar.month, calendar.long, locale.getdefault()).touppercase(); result1.add(monthname); } db.close();
for example, cursor returns 6, instead method returns getdisplayname july.
yes, would. because calendar.month
"logical field" 0-based. (crazy decision, but...)
basically need subtract 1 month number:
ca.set(calendar.month, monthnumero - 1);
for illustration calendar.january
documented having value of 0.
java android sqlite date calendar
No comments:
Post a Comment