java.lang.IllegalArgumentException: Illegal pattern character 'Y' for SimpleDateFormat

后端 未结 6 1554
小蘑菇
小蘑菇 2020-12-18 17:44

The following code:

Calendar now = Calendar.getInstance();
month = now.get(Calendar.MONTH) + 1;
year = now.get(Calendar.YEAR);
System.out.println(\"Month \"          


        
6条回答
  •  我在风中等你
    2020-12-18 18:19

    i have taken this table from java docs.

    Letter  Date or Time Component  Presentation    Examples
    G   Era designator  Text    AD
    y   Year    Year    1996; 96
    M   Month in year   Month   July; Jul; 07
    w   Week in year    Number  27
    W   Week in month   Number  2
    D   Day in year Number  189
    d   Day in month    Number  10
    F   Day of week in month    Number  2
    E   Day in week Text    Tuesday; Tue
    

    In your case just replace"Y" to "y" you can see Docs here

提交回复
热议问题