日期:2014-05-20 浏览次数:20771 次
public static void main(String[] args) { Calendar preDate = Calendar.getInstance(); Calendar now = Calendar.getInstance(); preDate.set(2007, 0, 1);// 月份从0开始 String year = (now.get(Calendar.YEAR) - preDate.get(Calendar.YEAR)) + ""; String month = (now.get(Calendar.MONTH) - preDate.get(Calendar.MONTH)) + ""; year = year.length() == 1 ? "0" + year : year; month = month.length() == 1 ? "0" + month : month; System.out.println(year + month); }
------解决方案--------------------
SimpleDateFormat 名字 = new SimpleDateFormat("yyyyMMdd");
System.out.println(名字.format(new Date()));
生成的就是20080821