Android - Format Timestamp in ListView with Cursor Adapter

前端 未结 3 536
迷失自我
迷失自我 2021-01-05 04:57

I am using a SimpleCursorAdapter to populate an Android ListView, and was wondering how I should go about getting all of the timestamps I get from a database, each in \"DATE

3条回答
  •  再見小時候
    2021-01-05 05:37

    I found it easiest to do the following:

    SimpleDateFormat oldTime = new SimpleDateFormat("HH:mm:ss");
    SimpleDateFormat newTime = new SimpleDateFormat("hh:mm:ss a");
    
    String stringTime;
    
    try {
    
            String reformattedStr = newTime.format(oldTime.parse(stringTime));
            } catch (ParseException e) {
            e.printStackTrace();
            }
    

提交回复
热议问题