日期:2014-05-18  浏览次数:20762 次

诡异的string 转化为timestamp!求助中!!!
我的string格式是2007年2月1日  
这样的格式  
似乎不能用valueof  
我在网上找了下边的转换方法,但还是用不成  
String   newsTimeTemp=ISOConverter(request.getParameter( "atime "));  
SimpleDateFormat   dateFormat=new   SimpleDateFormat( "yyyy-mm-dd   HH:MM:SS ");  
Date   date=dateFormat.parse(newsTimeTemp);//提示错误:Type   mismatch:   cannot   convert   from   Date   to   Date  

Timestamp   newsTime=new   Timestamp(date.getTime());  



------解决方案--------------------
String dateStr= "2007年2月1日 ";
try {
SimpleDateFormat sdf1=new SimpleDateFormat( "yyyy-MM-dd HH:mm:SS ");
String newDateStr=sdf1.format(DateFormat.getDateInstance(DateFormat.LONG).parse(dateStr));
System.out.println(newDateStr);
} catch (ParseException e) {
e.printStackTrace();
}

注意此串的大小写:yyyy-MM-dd HH:mm:SS