Calendar


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Calendar

  1. #1
    BlueLaser Guest

    Calendar


    I've got two questions regarding the use of the calendar class.

    I want to have the user enter in the day, month and year. But i would like
    the system to check whether the values entered by the user are consistent.
    Is it possible to do so?


    The next question is when i set a calendar pDate to month=5, why does it
    show up as month=6 when i print it out?It's fine with year and day. The only
    solution is to decrement the month parameter by 1 but i'm just wondering
    why.

    Calendar pDate=Calendar.getInstance();
    pDate.set(year, month, Date);
    System.out.println(pDate.getTime());

  2. #2
    Avrom Guest

    Re: Calendar


    Żo???er" <seanygoh@rocketmail.com> wrote:
    >
    >I've got two questions regarding the use of the calendar class.
    >
    >I want to have the user enter in the day, month and year. But i would like
    >the system to check whether the values entered by the user are consistent.
    >Is it possible to do so?


    I am assuming that you want to check whether the day is consistent with the
    number of days in that month (e.g. if it is April, then he must enter between
    1-30). You can check the maximum amount for days (and months etc.) using
    the method getActualMaximum() (I beleive that is the method's name). Look
    at the Javadocs for more info. I'll let you figure out the rest.

    >
    >
    >The next question is when i set a calendar pDate to month=5, why does it
    >show up as month=6 when i print it out?It's fine with year and day. The

    only
    >solution is to decrement the month parameter by 1 but i'm just wondering
    >why.
    >
    >Calendar pDate=Calendar.getInstance();
    >pDate.set(year, month, Date);
    >System.out.println(pDate.getTime());


    This is because months start at 0. Thus, setting it to 5 is the 6th month
    (June). What you want to do is subtract 1 if they are entering a number.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center