Now a days I take care of sensitive coding rather than completing the code anyhow.
So have a look at this code.
I am trying to check the Date Format.
I am here assuming that the date separator string is either "-" or "/".
First I thought to do it using Regular Expression, but I am new to Regular Expression.
So experts please do some comments here to improve the sensitivity of this code.
[code=java]
Date checkDate(Strin g date)throws Exception {
Date temp_d;
try{
temp_d = d.parse(date);
StringTokenizer st = new StringTokenizer (date,"-");
int m = Integer.parseIn t(st.nextToken( ))-1,
d = Integer.parseIn t(st.nextToken( )),
y = Integer.parseIn t(st.nextToken( ));
c.setTime(temp_ d);
if(m!=c.get(Cal endar.MONTH) || d!=c.get(Calend ar.DATE) || y!=c.get(Calend ar.YEAR)) throw new Exception("Wron g date format");
return temp_d;
}catch(Exceptio n e)
{
throw e;
}
}
[/code]
Please do some comments on it.
Is anything there to improve the logic :-)
Kind regards,
Dmjpro.
So have a look at this code.
I am trying to check the Date Format.
I am here assuming that the date separator string is either "-" or "/".
First I thought to do it using Regular Expression, but I am new to Regular Expression.
So experts please do some comments here to improve the sensitivity of this code.
[code=java]
Date checkDate(Strin g date)throws Exception {
Date temp_d;
try{
temp_d = d.parse(date);
StringTokenizer st = new StringTokenizer (date,"-");
int m = Integer.parseIn t(st.nextToken( ))-1,
d = Integer.parseIn t(st.nextToken( )),
y = Integer.parseIn t(st.nextToken( ));
c.setTime(temp_ d);
if(m!=c.get(Cal endar.MONTH) || d!=c.get(Calend ar.DATE) || y!=c.get(Calend ar.YEAR)) throw new Exception("Wron g date format");
return temp_d;
}catch(Exceptio n e)
{
throw e;
}
}
[/code]
Please do some comments on it.
Is anything there to improve the logic :-)
Kind regards,
Dmjpro.
Comment