1

サーバーからこの形式の Json オブジェクトを取得していますが、"Date": "/Date(1337032800000+0000)/"「4 月 1 日」のようにする必要があります。

私はこのように解析しようとしていますが、常に次のようになります"Unparseable date" message:

mDate = jsonArray.getJSONObject(i).getString("Date");
                    String shortDate = mDate.substring(6, mDate.length()-7);
                    String format="yyyy-MM-dd";
                    SimpleDateFormat sdf = new SimpleDateFormat(format);
                    try {
                        Date date = sdf.parse(shortDate);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }

よろしくお願いします!

4

2 に答える 2

2

元のレスポンスを replace /Date/のように変更する必要があります

String data = "/Date(1337032800000+0000)/";
String result = data.replaceAll("^/Date\\(" , "");
result = result.substring(0, result.indexOf('+'));

これ1337032800000で、ミリ秒単位の日付がわかりました。

于 2012-05-15T10:49:20.593 に答える
2

これはタイムスタンプですか?String を long に変更しない理由と:

Date date = new Date();
date.setTime(yourLongVariable);

月:

    int month = date.getMonth();

    months = " " + res.getString(R.string.january);
    if(month == 2)
    {
        months = " " + res.getString(R.string.febuary);
    }
    else if(month == 3)
    {
        months = " " + res.getString(R.string.march);
    }
    else if(month == 4)
    {
        months = " " + res.getString(R.string.april);
    }
    else if(month == 5)
    {
        months = " " + res.getString(R.string.may);
    }
    else if(month == 6)
    {
        months = " " + res.getString(R.string.june);
    }
    else if(month == 7)
    {
        months = " " + res.getString(R.string.july);
    }
    else if(month == 8)
    {
        months = " " + res.getString(R.string.august);
    }
    else if(month == 9)
    {
        months = " " + res.getString(R.string.september);
    }
    else if(month == 10)
    {
        months = " " + res.getString(R.string.october);
    }
    else if(month == 11)
    {
        months = " " + res.getString(R.string.november);
    }
    else if(month == 12)
    {
        months = " " + res.getString(R.string.december);
    }

これがプロではないことは知っていますが、私にとってはうまくいきます。

于 2012-05-15T10:48:36.867 に答える