String datevalue="2006-10-10 20:22:10.0";
   SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         try {
Date d=formater.parse(datevalue);
System.out.println(d);
} catch (ParseException e) {                       e.printStackTrace();
}
为什么打出来的还是Tue Oct 10 20:22:10 CST 2006
而不是:2006-10-10 20:22:10
如何能让、Date d=formater.parse(datevalue);
System.out.println(d);
打出的是2006-10-10 20:22:10

解决方案 »

  1.   

    你没有用DateFormat类啊,应该是:String datevalue = "2006-10-10 20:22:10.0";
    SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    try {
    Date d = formater.parse(datevalue);
    System.out.println(formater.format(d));
    } catch (ParseException e) {
    e.printStackTrace();
    }
      

  2.   

    Date d=formater.parse(datevalue);
    System.out.println(d);
    直接打印Date类对象d,会默认调用d.toString();方法,而此方法打印格式就是:
    Tue Oct 10 20:22:10 CST 2006
    要打印你需要的格式应该:
    System.out.println(formater.format(d));
      

  3.   

    楼主没有使用format()方法进行格式化,parse()只是构造一个date实例,但是这个实例不是你想要的格式化的,想要格式化的需要format()来执行,就像楼上说的。