给你参考这个列子吧import java.text.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class MyFormatDate {
public String getFormat(String chStr)
{
String format=null;
SimpleDateFormat sdf1 = new SimpleDateFormat( "yyyy/MM/dd kk:mm:ss" );
SimpleDateFormat sdf2 = new SimpleDateFormat( "yyyy年MM月dd日 kk时mm分ss秒 );
try{ Date dt;
dt=sdf1.parse(chStr);
System.out.println("1111111 "+dt);
format=sdf2.format(dt);
System.out.println("2222222 "+format);
}
catch(Exception e){
System.out.println(e.getMessage()); } return format;
}
public static void main(String[] args) {
MyFormatDate mfd=new MyFormatDate();
String a=mfd.getFormat("2004/07/13 12:12:33.000");
System.out.println(a);
}
}
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class MyFormatDate {
public String getFormat(String chStr)
{
String format=null;
SimpleDateFormat sdf1 = new SimpleDateFormat( "yyyy/MM/dd kk:mm:ss" );
SimpleDateFormat sdf2 = new SimpleDateFormat( "yyyy年MM月dd日 kk时mm分ss秒 );
try{ Date dt;
dt=sdf1.parse(chStr);
System.out.println("1111111 "+dt);
format=sdf2.format(dt);
System.out.println("2222222 "+format);
}
catch(Exception e){
System.out.println(e.getMessage()); } return format;
}
public static void main(String[] args) {
MyFormatDate mfd=new MyFormatDate();
String a=mfd.getFormat("2004/07/13 12:12:33.000");
System.out.println(a);
}
}
是什么格式啊,用SimpleDateFormat如何解析出来呢
SimpleDateFormat parser = new SimpleDateFormat("MM d yyyy H:mmaa");
Date date = parser.parse(intime);//这里出错,intime是String"07 1 2004 3:39PM"
sdf.format(intime)试试
SimpleDateFormat parser = new SimpleDateFormat("MM d yyyy h:mmaa", Locale.ENGLISH);//日期显示类型String intime = "2004-7-1 15:39:41";//数据库中的初始数据
System.out.println(intime);//打印确认
intime = parser.format(fmt.parse(intime));//转化为日期显示类型
System.out.println(intime);//打印确认
intime = fmt.format(parser.parse(intime));//再转化为数据库中的日期类型
System.out.println(intime);//打印确认
原帖在这儿:http://community.csdn.net/Expert/topic/3191/3191069.xml?temp=.5401728
我用你得方法
还是在Date date = parser.parse(intime);出错
可是使用结果集的getTimestamp("")方法取得java.sql.TimeStamp对象,然后调用toString()方法就可以得到需要的结果