String转成Date用DateSimpleFormat这个类 Calendar cal = Calendar.getInstance(); cal.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("2011-04-22")); have a try
public String getTime(int year,int month,int Nowdate){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd "); Date date = new Date(); date.setYear(year); date.setMonth(date.getMonth()-2); //设置月份 date.setDate(Nowdate); String time = sdf.format(date); }
Calendar cal = Calendar.getInstance();
cal.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("2011-04-22"));
have a try
public String getTime(int year,int month,int Nowdate){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd ");
Date date = new Date();
date.setYear(year);
date.setMonth(date.getMonth()-2); //设置月份
date.setDate(Nowdate); String time = sdf.format(date);
}