Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Blind dates.

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is odd... I don't understand what's happening. I'm trying to convert a string to a util.date. Here's what I've got:
SimpleDateFormat fDate = new SimpleDateFormat ( "MM/dd/yy" );
String expDate = request.getParameter( "expDate" );
ParsePosition pos = new ParsePosition(0);
java.sql.Date sqlExpDate = null;
java.util.Date uDate = new java.util.Date();
if ( expDate.compareTo( "" ) != 0 ) {
out.println( "expDate = " + expDate + "<br>" );
out.println( "sqlExpDate before = " + sqlExpDate + "<br>" );
try {
uDate = ( java.util.Date )fDate.parse( expDate, pos );
out.println( "uDate = " + uDate + "<br>" );
sqlExpDate = new java.sql.Date(uDate.getTime());
} catch ( Exception e ) {
lError = lError.concat( "<font color=red>Expiration Date not valid</font><br>" );
expDate = "";
}
out.println( "sqlExpDate = " + sqlExpDate + "<br>" );
}
And here's what I'm getting:
expDate = 30/09/02
sqlExpDate before = null
uDate = Wed Jun 09 00:00:00 EDT 2004
sqlExpDate = 2004-06-09
This doesn't make sense to me... How is it turning Sept 30, 2002 into Jun 9, 2004?
I appreciate any help-
Thanks.
 
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"MM/dd/yy" should be "dd/MM/yy"
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic