获取今天,昨天,前天的日期

		SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");//格式
		//今天
		String today=df.format(new Date());
		System.out.println(today);
		//昨天
		Calendar   cal   =   Calendar.getInstance();//日历
		cal.add(Calendar.DATE,   -1);
		String yesterday = new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime());
		System.out.println(yesterday);
		
		//前天
		cal.add(Calendar.DATE,   -1);
		String vorgestern = new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime());
		System.out.println(vorgestern);

猜你喜欢

转载自greypenguin.iteye.com/blog/2079388
今日推荐