Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

date

 
Jackie Wang
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess this question was asked before.
How I can check the validation of date?
says:
A string
"8/4/02" or "09/11/2002" is valid
while
"08042002" or "02/31/2002" is invalid?
 
Jackie Wang
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know whether this will help
java.text.DateFormat.getDateInstance().parse(dateString) throws a ParseException
but i don't know how to use it.
Any one can help? Thanks! =)
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You use it exactly as you wrote it. dateString is the date you want to check. If the date can not be converted into a valid date, it throws a parse exception. If you want the date to be in a specific format in order to be determined to be valid then you can use the SimpleDateFormat class to define a format.
 
Jackie Wang
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks tom, but anything wrong w/ that, and how can i modify as a method which only return a boolean? thanks
 
Jackie Wang
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think this class is working. but instead of throwing exception from a class, I just want a method returning a boolean. Is that possible? Thanks!
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure!

[ September 11, 2002: Message edited by: Thomas Paul ]
 
Jackie Wang
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it. thanks tom, i appreciated it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic