Why are months off by one with Java SimpleDateFormat?

后端 未结 5 968
野趣味
野趣味 2020-12-11 04:53

I am using SimpleDateFormat to display a Calendar like this :

public String getDate()
{
    String DATE_FORMAT = \"EEEE, dd/MM/yyyy HH:mm:ss\";
    SimpleDat         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-11 05:36

    the getMonth method in Date is 0 indexed. from the JavaDoc:

    Returns a number representing the month that contains or begins with the instant in time represented by this Date object. The value returned is between 0 and 11, with the value 0 representing January.

提交回复
热议问题