Commit 6775d890 authored by yanzg's avatar yanzg

默认日期格式的支持

parent 72e1179c
......@@ -855,4 +855,24 @@ public class DateHelper {
return false;
}
}
private static final long HOUR_UNIT = 1000 * 60 * 15;
/**
* 获取小时中的刻度时间
*
* @param from 来源时间
* @return
*/
public static String getHourUnitTime(Object from) {
Date dateTime = getDateTime(from);
if (dateTime == null) {
return null;
}
Date hour = DateHelper.getDateTime(DateHelper.getDateTimeString("yyyy-MM-dd HH:00:00.000", dateTime));
long totalMill = dateTime.getTime() - hour.getTime();
long unit = totalMill / HOUR_UNIT;
Date to = new Date(hour.getTime() + unit * HOUR_UNIT);
return DateHelper.getDateTimeString(to);
}
}
......@@ -19,5 +19,8 @@ public class TestDateHelper {
System.out.println("本月:" + DateHelper.getDateTimeString(DateHelper.getMonthEnd(date)));
System.out.println("本季度:" + DateHelper.getDateTimeString(DateHelper.getMonth3Start(date)));
System.out.println("本季度:" + DateHelper.getDateTimeString(DateHelper.getMonth3End(date)));
System.out.println("当前时间刻度:" + DateHelper.getHourUnitTime(new 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