java工具日期部分

package cn.jxsme.util.tool;

import java.sql.Date;
import java.sql.Time;
import java.util.Calendar;


/*
* autho huangjin green eat 
*Oct 20, 2008
*/

public class DataTool {
public static Date getNowDate(){
java.sql.Date currDate=new  java.sql.Date(new   java.util.Date().getTime());//得到当前日期。
return currDate;
}

public static Time getNowTime(){
java.sql.Time currTime=new  java.sql.Time(new   java.util.Date().getTime());//得到当前时间。
return currTime;
}

public static Integer getNowYear(){
Calendar   cal   =   Calendar.getInstance(); 
  return cal.get(Calendar.YEAR); 
}

public static Integer getNowMonth(){
Calendar   cal   =   Calendar.getInstance(); 
  return cal.get(Calendar.MONTH)+1; 
}

public static Integer getNowDay(){
Calendar   cal   =   Calendar.getInstance(); 
  return cal.get(Calendar.DAY_OF_MONTH); 
}

public static String getDateTimeString(){
return DataTool.getNowDate()+" "+DataTool.getNowTime();
}

//计算间隔天数
    public static long diffdays(java.util.Date date0,java.util.Date date1){
   long time0=date0.getTime();
   long time1=date1.getTime();
   return ((time1-time0)/(1000*60*60*24));
}

}

你可能感兴趣的:(java,sql)