Commit 929e5963 authored by 张永's avatar 张永

增加某个月的最后一天

parent 6a5080cc
......@@ -275,9 +275,6 @@ public class DateUtil {
}
}
public static void main(String[] args) {
System.out.println(format(Integer.MAX_VALUE));
}
/**
* 计算指定时间当天的开始时间
......@@ -476,6 +473,16 @@ public class DateUtil {
return c.getTime();
}
public static void main(String[] args) {
System.out.println(getLastMonth(FMT_DATE,-1));
System.out.println(getLastMonthAndLastDay(FMT_DATE,-1));
}
/**
*
*  * 获取指定日期下个月的第一天 的日期
......@@ -499,6 +506,7 @@ public class DateUtil {
return null;
}
//获取某月的第一天
public static String getLastMonth(String format, int month) {
try {
SimpleDateFormat sdf = new SimpleDateFormat(format);
......@@ -513,6 +521,22 @@ public class DateUtil {
return null;
}
//获取某月的最后一天
public static String getLastMonthAndLastDay(String format, int month) {
try {
SimpleDateFormat sdf = new SimpleDateFormat(format);
// 获取前一个月第一天
Calendar calendar1 = Calendar.getInstance();
calendar1.add(Calendar.MONTH, month);
calendar1.set(Calendar.DAY_OF_MONTH, calendar1.getActualMaximum(Calendar.DAY_OF_MONTH));
return sdf.format(calendar1.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String getTimeStamp() {
return String.valueOf(System.currentTimeMillis() / 1000);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment