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));
}
/**
* 计算指定时间当天的开始时间
......@@ -475,7 +472,17 @@ public class DateUtil {
c.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
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);
......@@ -512,6 +520,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