String temp = rs.getString(3); temp为2009-08-05 17:36:00
怎么转为Date型的2009-08-05 17:36:00
Date date ;
最后date为2009-08-05 17:36:00
------解决方案--------------------------------------------------------
- Java code
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String temp = rs.getString(3);Date date = sd.parse(temp);
------解决方案--------------------------------------------------------
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date d = sd.parse("2009-08-05 17:36:00");
------解决方案--------------------------------------------------------
如果你数据库中时date型,
String temp = rs.getString(3); 改成rs.getDate(3)
如果数据库中是varchar
- Java code
import java.text.DateFormat;import java.text.SimpleDateFormat;import java.util.Date;public class test { public static void main(String[] args) throws Exception { DateFormat fmt =new SimpleDateFormat("yyyy-MM-dd"); String s = "1987-10-10"; Date date = fmt.parse(s); System.out.println(fmt.format(date)); }}
------解决方案--------------------------------------------------------
SimpleDateFormat