-
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());
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks