packagexingzhi.tools;importjava.text.DateFormat;importjava.text.ParseException;importjava.text.SimpleDateFormat;importjava.util.Calendar;importjava.util.Date;importjava.util.Locale;/*** 对象帮助类.
*@authorxingzhi 2020年4月28日 上午9:12:32
**/
public classDateHelper {/*** 日历对象
*@authorxingzhi 2020年6月5日 下午4:22:32*/
private staticCalendar cal;/*** 初始化日历对象.
*@authorxingzhi 2020年6月5日 上午9:16:27*/
private static voidInitial() {if(cal == null) {
cal=Calendar.getInstance();
}
}/*** 获取当前时间对象
*@authorxingzhi 2020年4月28日 下午9:11:54
*@return
*/
public staticDate GetCurrentDate() {
Date d= newDate();returnd;
}/*** 获取指定日期的年.
*@authorxingzhi 2020年6月5日 下午4:23:26
*@paramd
*@return
*/
public static intGetDateForYear(Date d) {
Initial();
cal.setTime(d);returncal.get(Calendar.YEAR);
}/*** 获取指定日期的月份
*@authorxingzhi 2020年6月5日 上午9:24:17
*@return返回一个整数表示的月份值.从0-11.*/
public static intGetDateForMonth(Date d) {
Initial();
cal.setTime(d);returncal.get(Calendar.MONTH);
}/*** 获取指定日期每月的天数.
*@authorxingzhi 2020年6月5日 上午9:29:58
*@paramd
*@return
*/
public static intGetDateForDay(Date d) {
Initial();
cal.setTime(d);returncal.get(Calendar.DATE);
}/*** 获取指定日期的小时数.
*@authorxingzhi 2020年6月5日 上午9:32:21
*@return
*/
public static intGetDateForHour(Date d) {
Initial();
cal.setTime(d);returncal.get(Calendar.HOUR);
}/*** 获取指定日期的分钟数.
*@authorxingzhi 2020年6月5日 上午9:32:21
*@return
*/
public static intGetDateForMinute(Date d) {
Initial();
cal.setTime(d);returncal.get(Calendar.MINUTE);
}/*** 获取指定日期的秒数.
*@authorxingzhi 2020年6月5日 上午9:32:21
*@return
*/
public static intGetDateForSecond(Date d) {
Initial();
cal.setTime(d);returncal.get(Calendar.SECOND);
}
}