java中获得当前时间(yyyy-mm-dd)

代码越简单越好!不要太复杂。谢谢!

import java.text.SimpleDateFormat;
import java.util.Date;
Date d=new Date();//获取时间
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");//转换格式
System.out.println(sdf.format(d));//打印
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-08-11
Date d=new Date();//获取时间
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd kk:mm:ss ");//转换格式
System.out.println(sdf.format(date));//打印本回答被提问者采纳
第2个回答  2008-11-12
public static String getSystemTime()
{
return new SimpleDateFormat("yyyy-MM-dd").format(new Date(System.currentTimeMillis()));
}
这个方法就可以得到, 静态的, 用类名.方法名.
第3个回答  2008-11-12
public class MyDate {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Date date = new Date();
DateFormat matter = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(matter.format(date));
}
}
第4个回答  2008-11-12
public class Test {
public static void main(String[] args) {
Date date = new Date();
DateFormat df = DateFormat.getDateInstance();
System.out.println(df.format(date));
}
}