Commit e74c2de1 by zhengxj

finish 新增获取过去日期方法 on 20190128 by zhengxj

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@17173 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent 9c45ee3d
...@@ -42,8 +42,8 @@ public class DateUtil { ...@@ -42,8 +42,8 @@ public class DateUtil {
public static void main(String args[]){ public static void main(String args[]){
System.out.println(getCurrentDate()); // ;
System.out.println(parseDateYmd(getTomorrow())); System.out.println(getPastMonthLastDay(2));
} }
/** /**
...@@ -601,9 +601,47 @@ public class DateUtil { ...@@ -601,9 +601,47 @@ public class DateUtil {
} }
/** /**
* 得到过去数个月的第一天日期
*/
public static String getPastMonthFistDay(Integer pastMonth) {
//上个月最后一天
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, -pastMonth); //加一个月
calendar.set(Calendar.DATE, 1); //设置为该月第一天
// calendar.add(Calendar.DATE, -1); //再减一天即为上个月最后一天
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
return df.format(calendar.getTime());
}
/**
* 得到过去数个月的最后一天日期
*/
public static Date getPastMonthLastDay(Integer pastMonth) {
//上个月最后一天
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, -(pastMonth-1)); //加一个月
calendar.set(Calendar.DATE, 1); //设置为该月第一天
calendar.add(Calendar.DATE, -1); //再减一天即为上个月最后一天
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
return calendar.getTime();
}
/**
* 得到上个月的第一天 * 得到上个月的第一天
*/ */
public static String getLastMonthFirstDay() { public static Date getLastMonthFirstDay() {
//上个月第一天
GregorianCalendar gcLast = (GregorianCalendar) Calendar.getInstance();
gcLast.setTime(new Date());
gcLast.add(Calendar.MONTH, -1);
gcLast.set(Calendar.DAY_OF_MONTH, 1);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
return gcLast.getTime();
}
/**
* 得到指定日期上个月的第一天
*/
public static String getLastMonthFirstDay(Date date) {
//上个月第一天 //上个月第一天
GregorianCalendar gcLast = (GregorianCalendar) Calendar.getInstance(); GregorianCalendar gcLast = (GregorianCalendar) Calendar.getInstance();
gcLast.setTime(new Date()); gcLast.setTime(new Date());
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!