Commit dd77cfc9 authored by yanzg's avatar yanzg

压缩视频

parent b7e5a348
......@@ -18,6 +18,7 @@ import java.util.Date;
public class DateHelper {
private static final String FORMAT_YEAR_STRING = "yyyy-01-01";
private static final String FORMAT_YEAR_END_STRING = "yyyy-12-31";
private static final String FORMAT_MONTH_STRING = "yyyy-MM-01";
private static final String FORMAT_DAY_STRING = "yyyy-MM-dd";
private static final String FORMAT_DAY_HOUR_STRING = "yyyy-MM-dd HH:00:00";
......@@ -249,6 +250,14 @@ public class DateHelper {
return begin;
}
private static void setDayEnd(Calendar cal) {
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
cal.set(Calendar.MILLISECOND, 999);
}
/**
* 获取某一天起始和结束时间
*
......@@ -268,8 +277,7 @@ public class DateHelper {
*/
public static Date getDayEnd(Date date) {
Calendar end = getDayCalendarBegin(date);
end.add(Calendar.DAY_OF_MONTH, 1);
end.add(Calendar.SECOND, -1);
setDayEnd(end);
return end.getTime();
}
......@@ -281,7 +289,9 @@ public class DateHelper {
* @return 返回的日期
*/
public static Date getMonthStart(Date date) {
return DateHelper.getDateTime( getDate(date, FORMAT_MONTH_STRING));
Calendar cal = getDayCalendarBegin(date);
cal.set(Calendar.DAY_OF_MONTH, 1);
return cal.getTime();
}
/**
......@@ -293,6 +303,37 @@ public class DateHelper {
public static Date getMonthEnd(Date date) {
Calendar cal = getDayCalendarBegin(date);
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
setDayEnd(cal);
return cal.getTime();
}
/**
* 获取本季度开始时间
*
* @param date 某一天
* @return 返回的日期
*/
public static Date getMonth3Start(Date date) {
Calendar cal = getDayCalendarBegin(date);
int month = cal.get(Calendar.MONTH) / 3 * 3;
cal.set(Calendar.MONTH, month);
cal.set(Calendar.DAY_OF_MONTH, 1);
return cal.getTime();
}
/**
* 获得本月最后一天24点时间
*
* @param date 某一天
* @return 返回的值
*/
public static Date getMonth3End(Date date) {
Calendar cal = getDayCalendarBegin(date);
int month = cal.get(Calendar.MONTH) / 3 * 3;
cal.set(Calendar.MONTH, month + 2);
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
setDayEnd(cal);
return cal.getTime();
}
......@@ -303,7 +344,23 @@ public class DateHelper {
* @return 返回值
*/
public static Date getYearStart(Date date) {
return DateHelper.getDateTime( getDate(date, FORMAT_YEAR_STRING));
Calendar cal = getDayCalendarBegin(date);
cal.set(Calendar.MONTH, 0);
cal.set(Calendar.DAY_OF_MONTH, 1);
return cal.getTime();
}
/**
* 获取本年结束时间
*
* @param date 某一天
* @return 返回值
*/
public static Date getYearEnd(Date date) {
Calendar cal = getDayCalendarBegin(date);
cal.set(Calendar.MONTH, 11);
cal.set(Calendar.DAY_OF_MONTH, 31);
return cal.getTime();
}
/**
......@@ -601,7 +658,7 @@ public class DateHelper {
/**
* 增加分钟处理
*
* @param date 当前日期
* @param date 当前日期
* @param minute 需要增加的分钟
* @return 增加之后的值
*/
......@@ -615,7 +672,7 @@ public class DateHelper {
/**
* 增加秒处理
*
* @param date 当前日期
* @param date 当前日期
* @param second 需要增加的分钟
* @return 增加之后的值
*/
......
package helper;
import com.yanzuoguang.util.helper.DateHelper;
import org.junit.Test;
import java.text.ParseException;
import java.util.Date;
public class TestDateHelper {
@Test
public void testDateHelper() throws ParseException {
Date date = new Date();
System.out.println("本日:" + DateHelper.getDateTimeString(DateHelper.getDayStart(date)));
System.out.println("本日:" + DateHelper.getDateTimeString(DateHelper.getDayEnd(date)));
System.out.println("本年:" + DateHelper.getDateTimeString(DateHelper.getYearStart(date)));
System.out.println("本年:" + DateHelper.getDateTimeString(DateHelper.getYearEnd(date)));
System.out.println("本月:" + DateHelper.getDateTimeString(DateHelper.getMonthStart(date)));
System.out.println("本月:" + DateHelper.getDateTimeString(DateHelper.getMonthEnd(date)));
System.out.println("本季度:" + DateHelper.getDateTimeString(DateHelper.getMonth3Start(date)));
System.out.println("本季度:" + DateHelper.getDateTimeString(DateHelper.getMonth3End(date)));
}
}
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