This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Date Validation  RSS feed

 
Matt Hoffman
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to validate a date like such.. yyyy-mm-dd. I am using this following. The date will turn out to a funny number 1043-22-02 instead of a normal year, month, date. Any suggestions

public final class DateValidation
{

protected static boolean isDate(String string)
{
if (string == null)
return false;

if (string.indexOf("/") > -1)
{
try
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/mm/dd");
sdf.setLenient(false);
Date dt = sdf.parse( string );

return true;
}
catch(Exception e)
{
return false;
}
}
else
{
try
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
sdf.setLenient(false);
Date dt = sdf.parse( string );

return true;
}
catch(Exception e)
{
return false;
}
}
} //isDate
}
 
Cay Horstmann
author
Ranch Hand
Posts: 195
22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using MM instead of mm. Lowercase m is minutes in hour.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
y Year Year 1996; 96
M Month in year Month July; Jul; 07
D Day in year Number 189
d Day in month Number 10



this will help you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!