首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

date怎么获取年月日

2011-12-31 
date如何获取年月日RT,请大牛指教[解决办法]for exampleJava codeSimpleDateFormat sdf new SimpleDateF

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); 

热点排行