• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

checking validity of date with ddMM format

 
veena sasikumar
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I would like to check the validity of a string obtained from my GUI . It is in the format ddMM and when i used the following program, I coudn't get the required result. Please note that I have caught the Exceptions, but is not mentioned below.



I could read the reason for the behaviour from API doc and could get some information from archive. I could solve the problem by adding the current year with ddMM.

I would like to know whether there is a any other simple method to solve this problme.

Thanks in advance

Veena
 
Ajay Singh
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use this
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I would like to know whether there is a any other simple method to solve this problme.

what is the problem?

you've specified ddMM, so it will default to 1970, which is not a leap year
i.e. there's no 29 Feb 1970, so will error with setLenient(false)
 
veena sasikumar
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the replies.

My aim is to check the validity of the date for the present year, and for the coming years. What I meant is , if the date is a valid date for the present and next years, it should not throw exception and otherwise it should throw an exception.

When I run the code suggested by Ajay Singh, I got a result as "date is Sun Mar 01 00:00:00 GMT+05:30 1970". I want to get ParseException instead of this (This is the problem which I mentioned).

Also is there a method to check the validity of the date with respect to current year and next year by using java classes rather than checking the validity with respect to 1970.

Tha
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this might be one way



tests for current year.
for testing next year, just add 1 year to the calendar and re-test
 
veena sasikumar
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the immediate reply

I was unaware of the use of Calender class and the reply really helped a lot.

Thanks once again specially to Michael Dunn, Ajay Singh and JavaRanch

regards
veena
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A friend of mine once hand coded a COBOL table with 1231 entries in it and used mmdd as an index. In Java it would look something like ...

There was a special check for 0229 but that's it. The program did about 50 complex date functions with an astonishingly short execution path, something like 400 assembler instructions on the average call.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Boy, won't anything get a burst of outrage on this forum?
 
Henry Wong
author
Marshal
Pie
Posts: 21419
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stan James:
Boy, won't anything get a burst of outrage on this forum?


Sorry, COBOL, especially when used with CICS, is incredibly powerful. We are not stupid enough to challenge what it can do...

Henry
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree - I enjoyed COBOL and make a point of not saying bad things about it. But I actually liked that table of 1231 entries. All but 366 were empty. I still have the source if anybody needs it. You can guess how he determines if it's a leap year ... it's not with modulo 4.
[ January 25, 2007: Message edited by: Stan James ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic