import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class DateTest {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
// TODO 自动生成方法存根
//日期相减算出秒的算法
Date date1 = new SimpleDateFormat("yyyy-mm-dd").parse("2005-06-08");
Date date2 = new SimpleDateFormat("yyyy-mm-dd").parse("2006-06-12");
long l = date1.getTime()-date2.getTime()>0 ? date1.getTime()-date2.getTime():
date2.getTime()-date1.getTime();
//System.out.println(l/1000+"秒");
//日期相减得到相差的日期
long day = (date1.getTime()-date2.getTime())/(24*60*60*1000)>0 ? (date1.getTime()-date2.getTime())/(24*60*60*1000):
(date2.getTime()-date1.getTime())/(24*60*60*1000);
long day1=date1.getTime();
Date sb = new Date();
sb.setTime(day1);
System.out.println(Ds(30));
// System.out.println("相差的日期: " +day);
}
public static String Ds(int days){
SimpleDateFormat form=new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = Calendar.getInstance();
int day = calendar.get(Calendar.DAY_OF_YEAR);
calendar.set(Calendar.DAY_OF_YEAR, day - days);
Date cc = calendar.getTime();
return form.format(cc);
}
}
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class DateTest {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
// TODO 自动生成方法存根
//日期相减算出秒的算法
Date date1 = new SimpleDateFormat("yyyy-mm-dd").parse("2005-06-08");
Date date2 = new SimpleDateFormat("yyyy-mm-dd").parse("2006-06-12");
long l = date1.getTime()-date2.getTime()>0 ? date1.getTime()-date2.getTime():
date2.getTime()-date1.getTime();
//System.out.println(l/1000+"秒");
//日期相减得到相差的日期
long day = (date1.getTime()-date2.getTime())/(24*60*60*1000)>0 ? (date1.getTime()-date2.getTime())/(24*60*60*1000):
(date2.getTime()-date1.getTime())/(24*60*60*1000);
long day1=date1.getTime();
Date sb = new Date();
sb.setTime(day1);
System.out.println(Ds(30));
// System.out.println("相差的日期: " +day);
}
public static String Ds(int days){
SimpleDateFormat form=new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = Calendar.getInstance();
int day = calendar.get(Calendar.DAY_OF_YEAR);
calendar.set(Calendar.DAY_OF_YEAR, day - days);
Date cc = calendar.getTime();
return form.format(cc);
}
}