这是篇从百度知道转载过来的帖子,在此特别感谢提问者pingle_mice和回答者IceWee
解决方案如下:
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class DateTest { public static void main(String[] args) throws ParseException { String pattern = "yyyy-MM-dd"; SimpleDateFormat sdf = new SimpleDateFormat(pattern); String source = "2009-12-31"; Date date = sdf.parse(source); Calendar c = Calendar.getInstance(); c.setTime(date); Date today = c.getTime(); System.out.println("Today:/t/t" + today.toLocaleString()); c.add(Calendar.DAY_OF_YEAR, 1); Date today_plus1 = c.getTime(); System.out.println("Tomorrow:/t" + today_plus1.toLocaleString()); c.add(Calendar.DAY_OF_YEAR, 1); Date today_plus2 = c.getTime(); System.out.println("Today+2:/t" + today_plus2.toLocaleString()); c.add(Calendar.DAY_OF_YEAR, 1); Date today_plus3 = c.getTime(); System.out.println("Today+3:/t" + today_plus3.toLocaleString()); c.add(Calendar.DAY_OF_YEAR, 1); Date today_plus4 = c.getTime(); System.out.println("Today+4:/t" + today_plus4.toLocaleString()); c.add(Calendar.DAY_OF_YEAR, 1); Date today_plus5 = c.getTime(); System.out.println("Today+5:/t" + today_plus5.toLocaleString()); c.add(Calendar.DAY_OF_YEAR, 1); Date today_plus6 = c.getTime(); System.out.println("Today+6:/t" + today_plus6.toLocaleString()); c.add(Calendar.DAY_OF_YEAR, 1); Date today_plus7 = c.getTime(); System.out.println("Today+7:/t" + today_plus7.toLocaleString()); } }