Oct 10 00:00:00 UTC+0800 2010怎么转换成时间 2010-10-10这样的形式

Oct 10 00:00:00 UTC+0800 2010怎么转换成时间 2010-10-10这样的形式

[code="java"]
String str = "Oct 10 00:00:00 UTC+0800 2010";
DateFormat df = new SimpleDateFormat("MMM dd HH:mm:ss 'UTC'Z yyyy",Locale.ENGLISH);
Date date = df.parse(str);
System.out.println(date);
System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(date));
[/code]

好像只能把时间转换成yyyy-MM-dd这样格式的字符串,显示出来,而不能把某个Date实例格式化成yyyy-MM-dd这样的Date实例

[code="java"]
Date time=new Date();
DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
System.out.println(df.format(time));[/code]
而你把yyyy-MM-dd这样的字符串转变成Date实例,她的输出形式仍然是Oct 10 00:00:00 UTC+0800 2010
[code="java"]try{
Date dd=df.parse("2010-12-21");
System.out.println(dd);
}catch(Exception e){

    }[/code]