Commit 9d34f592 authored by yanzg's avatar yanzg

Merge branch 'ver1.1' of http://192.168.0.204/yzg/yzg-util

parents bb4f1f5b 9d6724cd
...@@ -24,6 +24,9 @@ public class DateHelper { ...@@ -24,6 +24,9 @@ public class DateHelper {
public static final String INIT_TIME = "00:00:00"; public static final String INIT_TIME = "00:00:00";
public static final String FORMAT_DAY_HOUR_STRING = "yyyy-MM-dd HH:00:00"; public static final String FORMAT_DAY_HOUR_STRING = "yyyy-MM-dd HH:00:00";
public static final String FORMAT_SECOND_STRING = "yyyy-MM-dd HH:mm:ss"; public static final String FORMAT_SECOND_STRING = "yyyy-MM-dd HH:mm:ss";
public static final int INIT_MILL_SECOND_NONE = 0;
public static final int INIT_MILL_SECOND_START = 1;
public static final int INIT_MILL_SECOND_END = 2;
private static final int MONTH_1 = 1; private static final int MONTH_1 = 1;
private static final int MONTH_2 = 2; private static final int MONTH_2 = 2;
...@@ -80,19 +83,21 @@ public class DateHelper { ...@@ -80,19 +83,21 @@ public class DateHelper {
* @param initMillSecond 是否初始化毫秒为0 * @param initMillSecond 是否初始化毫秒为0
* @return 结束时间 * @return 结束时间
*/ */
public static Date getDateTime(Object from, boolean initMillSecond) { public static Date getDateTime(Object from, int initMillSecond) {
if (StringHelper.isEmpty(from)) { if (StringHelper.isEmpty(from)) {
return null; return null;
} }
try { try {
Date to = null; Date to;
if (from instanceof Date) { if (from instanceof Date) {
to = (Date) from; to = (Date) from;
} else { } else {
to = DateAutoHelper.getAutoDate(String.valueOf(from)); to = DateAutoHelper.getAutoDate(String.valueOf(from));
} }
to = initMillSecond(to); if (initMillSecond == INIT_MILL_SECOND_NONE) {
return to; return to;
}
return initMillSecond(to, initMillSecond);
} catch (Exception ex) { } catch (Exception ex) {
ExceptionHelper.handleException(DateHelper.class, ex, from); ExceptionHelper.handleException(DateHelper.class, ex, from);
} }
...@@ -124,7 +129,7 @@ public class DateHelper { ...@@ -124,7 +129,7 @@ public class DateHelper {
* @return 结束时间 * @return 结束时间
*/ */
public static Date getDateTime(Object from) { public static Date getDateTime(Object from) {
return getDateTime(from, true); return getDateTime(from, INIT_MILL_SECOND_START);
} }
/** /**
...@@ -302,13 +307,21 @@ public class DateHelper { ...@@ -302,13 +307,21 @@ public class DateHelper {
/** /**
* 获取当天的日期 * 获取当天的日期
* *
* @param date 需要的日期 * @param date 需要的日期
* @param initMillSecond 初始化毫秒单位
* @return 返回的日期 * @return 返回的日期
*/ */
public static Date initMillSecond(Date date) { public static Date initMillSecond(Date date, int initMillSecond) {
if (initMillSecond == INIT_MILL_SECOND_NONE) {
return date;
}
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();
c.setTime(date); c.setTime(date);
c.set(Calendar.MILLISECOND, 0); if (initMillSecond == INIT_MILL_SECOND_START) {
c.set(Calendar.MILLISECOND, 0);
} else {
c.set(Calendar.MILLISECOND, 999);
}
return c.getTime(); return c.getTime();
} }
......
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