TA的每日心情 | 开心 2012-3-7 10:15 |
---|
签到天数: 11 天 [LV.3]偶尔看看II
|
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
* 获得系统的当前时间
* @param dateFormate 时间格式
* @return
*/
public static String getCurTime(SimpleDateFormat dateFormate){
Date date = new Date(System.currentTimeMillis());
return dateFormate.format(date);
}
/**
*
* @param begin 开始时间
* @param end 当前时间
* @param dateFormate 时间格式
* @return 两个时间点之间的差,单位小时
*/
public static long compareTime(String begin,String end,SimpleDateFormat dateFormate){
long hours = 0;
try {
Date date1 = dateFormate.parse(begin);
Date date2 = dateFormate.parse(end);
long diff = date2.getTime() - date1.getTime();
// int min= diff/(1000 * 60 ); //分钟
hours = diff/(1000 * 60* 60);//小时
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return hours;
} |
|