samedi 26 mars 2016

The date like "yyyy-MM-dd" in Android SQLite

How can I get the date_label to show the date in this format "yyyy-MM-dd" instead of milliseconds? Before I stored the date as String and it worked just fine but then I changed to long because that's the way to store dates according to many "experts" on this site.

private void fillData() {

    cursor = db.getAllWorkdays();

    String[] from = new String[] { DBAdapter.KEY_WEEKDAY, DBAdapter.KEY_DATE , DBAdapter.KEY_WORKSTART ,
            DBAdapter.KEY_WORKEND , DBAdapter.KEY_VAKT };
    int[] to = new int[] { R.id.textView_weekday, R.id.date_label, R.id.start_label, R.id.end_label, R.id.textView4 };

    //  create an array adapter and set it to display using our row

    SimpleCursorAdapter rows = new SimpleCursorAdapter(this,
            R.layout.list_row, cursor, from, to, 0);
    setListAdapter(rows);
}

This picture shows a running example

Aucun commentaire:

Enregistrer un commentaire