web-dev-qa-db-ja.com

dd / mm / yyyy vs dd / MM / yyyy?

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        String date = sdf.format(new Date()); 
        System.out.println(date); 

結果は今日の日付、つまり2014年3月23日です

しかし、私がするとき

 SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yyyy"); 

結果は、2014年5月23日、2014年5月23日、2014年6月23日、およびprgramの実行ごとに息子になります。なぜそうなのか?

13
user3198603

ドキュメント からわかるように、mmは月ではなく分であるためです。

39
T.J. Crowder
1. d/D: day without 0 prefix on single digit. 
2. dd/DD: day with 0 prefix if single digit.
3. M: Month without 0 prefix on single digit.
4. MM: Month with 0 prefix if single digit.
5. yy/YY: Last two digit of year.
6. yyyy/YYYY: represents full year.
7. HH: 24 hour based hour. ie. 13:00. **H** will display hour without prefix 0 if single digit
8. hh: 12 hour based hour. ie. 01:00. **h** will display hour without prefix 0 if single digit
9. m: minute without 0 prefix on single digit. 
10.mm: minute with 0 prefix if single digit.
11.s: second without 0 prefix on single digit. 
12.ss: second with 0 prefix if single digit.
13.tt: represent the AM or PM
25
Shell

mmは分を表すため、mmを使用すると、月ではなく分が出力されます。

MMは月を表します。

Time Patterns

5
Salah