java - calendar methods -


In addition to inbuilt functions, can we use any simple formula to calculate the month of the month of the month Yes, use the calendar object:

/ P>

  calendar cal = calendar.Ast Instance (); Cal.set (Calendar: IEER, 2009) Cal.set (Calendar. MONTH, Calendar .Jenie) // 0-based so that calendar. January is cal.set (calendar. DAY_OF_MONTH, 1)  

then:

  cal.get (Calendar. DAY_OF_WEEK); // is the calendar. Monday  

So you can easily prepare a method for this:

  / ** takes a 1-month time so that the 1 * / Public Intimate Daystart (int year, month) {calendar cal = calendar.justinstance (); Cal.set (calender.eEER, year) cal.set (calendar.month, month-1); Cal.set (calendar. DAY_OF_MONTH, 1); Back cal.get (Calendar. DAY_OF_WEEK); }  

Comments