?? dateutils.java
字號:
/*
* DateUtils.java
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Author: Winter Lau (javayou@gmail.com)
* http://dlog4j.sourceforge.net
*/
package com.liusoft.dlog4j.util;
import java.sql.Time;
import java.util.Calendar;
import java.util.Date;
/**
* 日期相關的工具類
* @author Winter Lau
*/
public class DateUtils extends org.apache.commons.lang.time.DateUtils{
/**
* 合并日期和時間
* @param date
* @param time
* @return
*/
public static Calendar mergeDateTime(Date date, Time time){
Calendar cal = Calendar.getInstance();
if(date!=null)
cal.setTime(date);
if(time!=null){
Calendar temp = Calendar.getInstance();
temp.setTime(time);
cal.set(Calendar.HOUR_OF_DAY, temp.get(Calendar.HOUR_OF_DAY));
cal.set(Calendar.MINUTE, temp.get(Calendar.MINUTE));
cal.set(Calendar.SECOND, temp.get(Calendar.SECOND));
cal.set(Calendar.MILLISECOND, temp.get(Calendar.MILLISECOND));
}
return cal;
}
/**
* 返回兩個日期相差的天數
* @param d1
* @param d2
* @return
*/
public static int diff_in_date(Date d1, Date d2){
return (int)(d1.getTime() - d2.getTime())/86400000;
}
/**
* 獲取某天開始的那一刻
* @param year
* @param month
* @param date
* @return
*/
public static Calendar getDateBegin(int year, int month, int date){
Calendar begin_time = Calendar.getInstance();
begin_time.set(Calendar.YEAR, year);
begin_time.set(Calendar.MONTH, month-1);
begin_time.set(Calendar.DATE, date);
begin_time.set(Calendar.HOUR_OF_DAY, 0);
begin_time.set(Calendar.MINUTE, 0);
begin_time.set(Calendar.SECOND, 0);
begin_time.set(Calendar.MILLISECOND, 0);
return begin_time;
}
/**
* 清除日歷的時間字段
* @param cal
*/
public static void resetTime(Calendar cal){
cal.set(Calendar.HOUR_OF_DAY,0);
cal.set(Calendar.MINUTE,0);
cal.set(Calendar.SECOND,0);
cal.set(Calendar.MILLISECOND,0);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -