java获取系统指定时间年月日
java获取系统指定时间年月日
1 private String setDateTime(String falg) { 2 Calendar c = Calendar.getInstance(); 3 c.setTimeInMillis(new Date().getTime()); 4 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 5 SimpleDateFormat dateMouthFormat = new SimpleDateFormat("yyyy-MM"); 6 SimpleDateFormat dateYearFormat = new SimpleDateFormat("yyyy"); 7 if (falg.equals("daystartTime")) { 8 c.add(Calendar.DATE, -45); 9 return dateFormat.format(c.getTime()); 10 } else if (falg.equals("dayendTime")) { 11 return dateFormat.format(c.getTime()); 12 } else if (falg.equals("MouthstartTime")) { 13 c.add(Calendar.YEAR, -1); 14 return dateMouthFormat.format(c.getTime()); 15 } else if (falg.equals("MouthendTime")) { 16 return dateMouthFormat.format(c.getTime()); 17 } else if (falg.equals("YearstartTime")) { 18 c.add(Calendar.YEAR, -3); 19 return dateYearFormat.format(c.getTime()); 20 } else if (falg.equals("YearendTime")) { 21 return dateYearFormat.format(c.getTime()); 22 } else { 23 return null; 24 } 25 }