The dates in my sqlite in android is saving 12/31/69 instead of the actual date. I have this in my db adapter:
+ KEY_DATE + " DATETIME DEFAULT CURRENT_TIMESTAMP
In my activity i have
Date date = new Date(cursor.getLong(cursor.getColumnIndex(mDbHelper.KEY_DATE)));
mDateFormat = DateFormat.getDateInstance(DateFormat.SHORT);
When I do a Log.d(“Debug”, mDateFormat.format(date)) it outputs 12/31/69 what am I doing wrong?
mDateFormatis just a date format – you haven’t used the value ofdatefrom the previous line anywhere. You want something like:Now that may still give the wrong value – but we can move on to that. It would really help if you’d show more of what’s in your adapter than the partial statement you’ve got there. We haven’t got nearly enough context.
EDIT: You’re calling
getLong, but you’ve got a default value of CURRENT_TIMESTAMP, which looks like it’ll come out as text:It’s unclear to me what you’d expect to happen when you fetch that value as a long… according to the documentation, the result is implementation-specific – I suspect it’s returning 0, giving you a date of the Unix epoch, which would make sense with your output if you’re in a time zone west of Greenwich.