Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JSP <input is '1/31/2003' how do I get it into a date field?

Status
Not open for further replies.

ablazso

Programmer
Oct 2, 2002
2
US
In my JSP code I have the following:

<input type=&quot;text&quot; name=&quot;fromDT&quot; value=&quot;<% strfDT %>&quot; ...

I need to convert this strfDT input, which is in mm/dd/yyyy format, to a valid date object. I tried to do the following but is does not work. I guess, because 'request.Paramterer'
does not process the special characters (/).

String strFromDT = request.Parameter(&quot;fromDT&quot;);
Date dtFromDT = new Date(strFromDT);


Can anyone tell me how best to handel this kind of requests?

Thanks in advance, Alex
 
Try this:


java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(&quot;MM/dd/yyyy&quot;);
Date dtFromDT = sdf.parse( strFromDT );

&quot;When you have eliminated the impossible, whatever remains, however
improbable, must be the truth.&quot; ~ Arthur Conan Doyle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top