• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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.
 
I'm not sure if I approve of this interruption. But this tiny ad checks out:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic