tags:

views:

33

answers:

1

In a Jsp I've got a input date String formatting as “Aug-6-2009”,how to change that to "2009-08-06" so that Mysql can read.

Maybe i need regex?

That may seem to be a easy question,but bear with me.

A: 

You can use a SimpleDateFormat object's .parse() and .format() methods to get a string in the format you need.

http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html

Amber
java.text.DateFormat.parse() is preferred over deprecated java.util.Date.parse().
Aleksi
Already updated the answer to reflect that (SimpleDateFormat inherit's DateFormat's parse method).
Amber
thx!it works~~~~~