aspose file tools*
The moose likes JSP and the fly likes Blind dates. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Blind dates." Watch "Blind dates." New topic
Author

Blind dates.

George Larry
Ranch Hand

Joined: Nov 07, 2001
Posts: 52
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.
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 565
"MM/dd/yy" should be "dd/MM/yy"

I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Blind dates.
 
Similar Threads
Need help with SQL Dates using Oracle
comparing dates
how to get the date from the string representation of date
Max Date Limit
Mapping Java Date to an Oracle Date.