• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Date Validation

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
}
 
author
Posts: 284
35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using MM instead of mm. Lowercase m is minutes in hour.
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic