package test;
import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar;public class date {
public static void main(String[] args) { Calendar c = new GregorianCalendar(); //获取当前年 int year=c.get(Calendar.YEAR) ; //获取当前月 int month=c.get(Calendar.MONTH)+1; //获取当前日 int day=c.get(Calendar.DATE) ; System.out.println(c.get(Calendar.DATE)+2); } //格式转换 public static String getString(Date date){ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); String str=df.format(date); return str; } //显示当天时间 public static Date getToDay(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.DAY_OF_MONTH, 0); date = calendar.getTime(); return date; } //显示后天时间 public static Date getNextDay(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.DAY_OF_MONTH, 2); date = calendar.getTime(); return date; } //显示前天时间 public static Date getyesterday(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.DAY_OF_MONTH, -1); date = calendar.getTime(); return date; } }