• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Validating Dates

 
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a program that accepts dates as a parameter and then validates the date so that 10th of October 2007 should be entered as 20071010. I wrote a probram to validate this but it's not working ok



any suggestions would be appreciated
 
Marshal
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

"yyyyddMM"

Year, Day, Month? Well, that would work okay for October 10 (day = month) but not so well for other choices.

 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> but it's not working ok

looks like you need to create the SimpleDateFormat object first
set its leniency to false sdf.setLenient(false);
then parse the date
 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Michael Dunn:
> but it's not working ok

looks like you need to create the SimpleDateFormat object first
set its leniency to false sdf.setLenient(false);
then parse the date



Thats what i finally did and now it works perfectly
my code is
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!