给你参考这个列子吧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);
  }
}

解决方案 »

  1.   

    我主要不知道"07  1 2004  3:39PM"
    是什么格式啊,用SimpleDateFormat如何解析出来呢
      

  2.   

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//数据库中类型
    SimpleDateFormat parser = new SimpleDateFormat("MM  d yyyy  H:mmaa");
    Date date = parser.parse(intime);//这里出错,intime是String"07  1 2004  3:39PM"
    sdf.format(intime)试试
      

  3.   

    你可以用StringTokenizer对象解析intime字符串得到日期和时间的各个部分,然后用这些数据组合Calendar对象,再格式化为你想要的字符串
      

  4.   

    修改了一点,示例代码如下SimpleDateFormat fmt = new SimpleDateFormat("yyyy-M-d HH:mm:ss");//数据库中类型
    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);//打印确认
      

  5.   

    其实我也是现学现用,^_^
    原帖在这儿:http://community.csdn.net/Expert/topic/3191/3191069.xml?temp=.5401728
      

  6.   

    zcjl() :
    我用你得方法
    还是在Date date = parser.parse(intime);出错
      

  7.   

    我觉得可以用 java.sql.TimeStamp。
    可是使用结果集的getTimestamp("")方法取得java.sql.TimeStamp对象,然后调用toString()方法就可以得到需要的结果