Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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

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"
 
reply
    Bookmark Topic Watch Topic
  • New Topic