Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This was my final solution.</p> <p>Please note that this is a hack that gets SQLite to reformat the date on retrieval. A better solution would be to store the date and retrieve it on its own.</p> <p>Have fields for retrieval keys:</p> <pre><code>public static final String KEY_TIMESTAMP = "timestamp"; public static final String KEY_DATESTAMP = "strftime('%d/%m/%Y'," + KEY_TIMESTAMP +")"; </code></pre> <p>Store the timestamp like normal in the database entry:</p> <pre><code>String timeStamp = new Timestamp( Calendar.getInstance().getTimeInMillis() ).toString(); ContentValues initialValues = new ContentValues(); ... initialValues.put(KEY_TIMESTAMP, timeStamp); return mDb.insert(DATABASE_TABLE, null, initialValues); </code></pre> <p>Where mDb is an SQLiteDatabase object.</p> <p>When retrieving the timestamp in <code>yyyy-MM-dd HH:mm:ss.SSS</code> format, use the regular <code>KEY_TIMESTAMP</code>.</p> <p>The following method retrieves a row with both items in there. Use the appropriate key for retrieval. </p> <pre><code>public Cursor fetchItem(long rowId) throws SQLException { Cursor cursor = mDb.query(true, DATABASE_TABLE, new String[] {KEY_ITEMID,KEY_TIMESTAMP,KEY_DATESTAMP}, KEY_ITEMID + "=" + rowId, null, null, null, null, null ); return cursor; } </code></pre> <p>Use the appropriate key for retrieval</p> <pre><code>mTimestamp = quote.getString( quote.getColumnIndex(QuotesDbAdapter.KEY_TIMESTAMP))); mDatestamp = quote.getString( quote.getColumnIndex(QuotesDbAdapter.KEY_DATESTAMP))); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload