package experiment1;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class Test02 {
public static void main(String[] args) {
Date nowTime=new Date();
System.out.println(nowTime);
SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
String nowTimeSdf=simpleDateFormat.format(nowTime);
System.out.println(nowTimeSdf);
Date time1=new Date(System.currentTimeMillis()+10*24*60*60*1000);
String sdfTime=simpleDateFormat.format(time1);
System.out.println(sdfTime);
Calendar calendar=Calendar.getInstance();
System.out.println("当前时间:"+calendar.get(Calendar.YEAR)+"年"+(calendar.get(Calendar.MONTH)+1)+"月"
+calendar.get(Calendar.DATE)+"日 "+calendar.get(Calendar.HOUR)+"时"
+calendar.get(Calendar.MINUTE)+"分"+calendar.get(Calendar.SECOND)+"秒");
calendar.add(Calendar.DATE,10);
System.out.println("10天后当前时间:"+calendar.get(Calendar.YEAR)+"年"+(calendar.get(Calendar.MONTH)+1)+"月"
+calendar.get(Calendar.DATE)+"日 "+calendar.get(Calendar.HOUR)+"时"
+calendar.get(Calendar.MINUTE)+"分"+calendar.get(Calendar.SECOND)+"秒");
}
}
package experiment1;
import java.util.Calendar;
public class Test04 {
public static void main(String[] args) {
Calendar c1=Calendar.getInstance();
c1.set(2001,9,12);
Calendar c2=Calendar.getInstance();
System.out.println("c1:"+c1.get(Calendar.YEAR)+"-"+c1.get(Calendar.MONTH)+"-"+c1.get(Calendar.DATE));
System.out.println("c2:"+c2.get(Calendar.YEAR)+"-"+c2.get(Calendar.MONTH)+"-"+c2.get(Calendar.DATE));
long day=(c2.getTimeInMillis()-c1.getTimeInMillis())/(24*60*60*1000);
System.out.println("c1和c1相隔:"+(day+30)+"天");
}
}