1

この形式の文字列として日付を含むsqlite列がありますyyyy-mm-dd、SimpleDateFormatで変換しようとしていますが、常に01-01-1970を返しますか?これは私のアダプタのコードです:

adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
    public boolean setViewValue(View view, Cursor cursor, int columnIndex) {

      if (view.getId() == R.id.swimm_date)
        { 
        int DateUSA = cursor.getInt(columnIndex);
        TextView tv = (TextView)view;
        DateFormat FormatDate = new SimpleDateFormat ("dd-MM-yyyy");
        String DateEUR = FormatDate.format(DateUSA);
        tv.setText(DateEUR);
        return true;
        }
4

3 に答える 3

1

たぶん、このコードフラグメントが役立ちます:

    adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            if (view.getId() == R.id.swimm_date) {
                DateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
                TextView tv = (TextView)view;
                tv.setText(sdf.format(java.util.Date.parse(cursor.getString(columnIndex))));
                return true;
            }
于 2013-01-10T09:39:30.910 に答える
0

ありがとう、私はすでにこの解決策で解決しました:

         if (view.getId() == R.id.swimm_date)
    { 
     Date parsed = new  Date();
     String DateUSA = cursor.getString(columnIndex);
     SimpleDateFormat fmt = new SimpleDateFormat ("yyyy-MM-dd");
     SimpleDateFormat fmtOut = new SimpleDateFormat ("dd-MM-yyyy");

     try {parsed = fmt.parse(DateUSA);}
     catch(ParseException pe) {
     System.out.println("ERROR: Cannot parse \"" + parsed + "\"");
     }
    String DateEUR = fmtOut.format(parsed);
    TextView tv = (TextView)view;
    tv.setText(DateEUR);
    return true;
    }
于 2013-01-30T16:19:11.003 に答える
0

これを使って :

public static String getCurrentDate() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        String date = dateFormat.format(new Date(System.currentTimeMillis()));
        return date;
    }
于 2013-01-30T15:31:59.113 に答える