0

2012 年 4 月 22 日の形式で日付を表示したい。私はこのコードを使用しています:

        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");

        sdf.applyPattern("dd MMM yyyy");
        Date x = new Date(time.year,time.month,time.monthday);
        System.out.println(sdf.format(x));

しかし、私は 22 apr 3912 として o/p を取得しています。2012 の代わりに 3912 が表示されている理由を知りたいです。

4

3 に答える 3

1
Calendar cal=Calendar.getInstance();
SimpleDateFormat sdf  = new SimpleDateFormat("dd MMM yyyy");
String dateresult = sdf.format(cal.getTime());
于 2012-04-22T18:59:58.703 に答える
1
SimpleDateFormat dateformate = new SimpleDateFormat("dd-MMM-yyyy");
    Calendar currentDate = Calendar.getInstance();

    String currentDateStr = dateformate.format(currentDate.getTime());
    Log.i("Infoe ", " " + currentDateStr.toString());       
    System.out.println("Current date is :  " + currentDateStr);
    ////=== OR

    SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");

    sdf.applyPattern("dd-MMM-yyyy");
    Date x = new Date(currentDate.get(Calendar.YEAR) - 1900,
            currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DAY_OF_MONTH));
    Log.i("Infoe ", " " + sdf.format(x));
    System.out.println(sdf.format(x));

その 3912 bcz .​​..日付は次のように設定されます... Calendar.set(年 + 1900、月、日) または GregorianCalendar(年 + 1900、月、日)。グレゴリオ暦に従って

日付は非推奨であるため、カレンダーの使用はgdだと思います... nd日付形式にはdd-MMM-yyyy no dd-MM-yyyy bczを使用します月の最初の2文字が必要です... 日付形式の場合

于 2012-04-22T19:14:01.827 に答える
1

DateクラスのAPIを読んでください。1900 年から始まるため、このコンストラクターでは日付 - 1900 を指定する必要があります。ただし、このコンストラクターは非推奨であるため、日付関連の操作には Calendar オブジェクトの使用を開始することをお勧めします。Java.da 用

于 2012-04-22T18:48:29.350 に答える