Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calendar questions 2

Status
Not open for further replies.

chals1

Technical User
Sep 3, 2003
73
ES
These prints results in 1 and 6.
shouldn't be 1(sunday) and 3(tuesday)?

Code:
import java.util.Calendar;

public class calendario {
   public static void main(String args[]) {
      Calendar now = Calendar.getInstance();
      System.out.println(now.get(Calendar.DAY_OF_WEEK));


      now.set(2004,12,14);
      System.out.println(now.get(Calendar.DAY_OF_WEEK));

   }
}

Another question.i'm stuck into getActualMaximum()
Why this is wrong?

System.out.println("The last day of month is:"+now.getActualMaximum(DAY_OF_MONTH));
 
You should use now.set(2004,11,14); if your target date is 14th december, month is counted from 0 to 11.

System.out.println("The last day of month is:"+now.getActualMaximum(Calendar.DAY_OF_MONTH)); will print 31

Please mark this post as helpful if the code suits you
 
the month field for set is 0-based, so you'd want to change that to 11, not 12. (Calendar.JANUARY == 0).<br><br>As far as your getActualMaximum goes... you'd want to change that to:<br><br>now.getActualMaximum(Calendar.DAY_OF_MONTH)<br><br>because DAY_OF_MONTH is a static variable within the Calendar class.<br><br>also, i should note that because you're setting the date to 2004, 12, 14, you're in fact checking the last day of january 2005. <p>Liam Morley<br><A HREF="mailto:"></A><br>&quot;light the deep, and bring silence to the world.<br>light the world, and bring depth to the silence.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top