Displaying dates in localized format on Android

前端 未结 1 1523
北恋
北恋 2020-12-14 02:09

I\'m currently building my first app for Android. What I\'m having trouble with is the storage and localized display of dates in connection with a SimpleCursorAdapter<

相关标签:
1条回答
  • 2020-12-14 02:33

    If you want to skip on the parsing, you could store the date as a long instead. Then you could just create a new Date object using the long with zero parsing.

    This isn't directly related to your question, but: One thing you might want to consider using is android.text.format.DateFormat for getting your date formatters. This way you format your dates/times to the user's locale settings instead of your own presets. It might also make your code simpler, as you don't need to create your own SimpleDateFormat anymore.

    With these two things in mind, you can get rid of the calls to your own methods:

    ((TextView) view).setText(android.text.format.DateFormat.getDateFormat().format(new Date(cursor.getString(columnIndex))));
    
    0 讨论(0)
提交回复
热议问题