Calendar.Month gives wrong output

后端 未结 4 1058
滥情空心
滥情空心 2020-11-28 16:09

I have been using java.util for all date and calendar representations. But I am facing a strange problem here. Calendar.MONTH, Calendar.DAY_O

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 16:55

        Calendar now = Calendar.getInstance();
        out.println("month now= " + (now.get(Calendar.MONTH)+1));
    

    OR with GregorianCalender:

        GregorianCalendar nu  = new GregorianCalendar();
        int day = nu.get(Calendar.DAY_OF_MONTH);
        int month = (nu.get(Calendar.MONTH)+1);  //month +1 because january`==0
        int year= nu.get(Calendar.YEAR);
        int hour= nu.get(Calendar.HOUR_OF_DAY);
        int minutes= nu.get(Calendar.MINUTE);
    

    here

提交回复
热议问题