日期:2014-05-20  浏览次数:20865 次

date如何获取年月日
RT,请大牛指教

------解决方案--------------------
for example
Java code
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date d = sdf.parse("2011-10-20");
Calendar c = Calendar.getInstance();
c.setTime(d);
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH) + 1;
int day = c.get(Calendar.DAY_OF_MONTH);
System.out.printf("year=%04d, month=%02d, day=%02d\n", year, month, day);