package publicclass;
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.Calendar;
|
import java.util.Date;
|
|
/**»ñÈ¡2¸öʱ¼äµÄÌìÊý¼ä¸ô*/
|
public class Gethour {
|
|
|
/**
|
*¼ÆËã2¸öÈÕÆÚÏà²îµÄÌìÊý
|
*/
|
public static int getday(String smdate) {
|
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
|
Calendar cal = Calendar.getInstance();
|
Date startDate=null;
|
Date endDate=null;
|
try {
|
startDate =sdf.parse(smdate);
|
endDate =sdf.parse(GetNowTime.y_m_d());
|
} catch (ParseException e) {
|
e.printStackTrace();
|
}
|
|
cal.setTime(startDate);
|
long time1 = cal.getTimeInMillis();
|
cal.setTime(endDate);
|
long time2 = cal.getTimeInMillis();
|
long between_days=(time2-time1)/(1000*3600*24);
|
return Integer.parseInt(String.valueOf(between_days));
|
}
|
|
/**
|
*¼ÆËã2¸öÈÕÆÚÏà²îµÄÌìÊý
|
*/
|
public static int getday2(String smdate) {
|
SimpleDateFormat sdf=new SimpleDateFormat("yyyy_MM_dd_HH");
|
Calendar cal = Calendar.getInstance();
|
Date startDate=null;
|
Date endDate=null;
|
try {
|
startDate =sdf.parse(smdate);
|
endDate =sdf.parse(GetNowTime.y_m_d());
|
} catch (ParseException e) {
|
e.printStackTrace();
|
}
|
|
cal.setTime(startDate);
|
long time1 = cal.getTimeInMillis();
|
cal.setTime(endDate);
|
long time2 = cal.getTimeInMillis();
|
long between_days=(time2-time1)/(1000*3600*24);
|
return Integer.parseInt(String.valueOf(between_days));
|
}
|
|
|
/**
|
* ¼ÆËã2¸öʱ¼äÏà²îµÄÌìÊý¡¢Ð¡Ê±¡¢·ÖÖÓ¡¢Ãë
|
* @param startTime ¿ªÊ¼Ê±¼ä
|
* @param endTime ½ØÖ¹Ê±¼ä
|
* @param format ʱ¼ä¸ñʽ yyyy-MM-dd HH:mm:ss
|
* @param str ·µ»ØµÄÊý¾ÝΪ£ºday-Ìì¡¢hour-Сʱ¡¢min-·ÖÖÓ¡¢second-Ãë
|
* @return
|
*/
|
@SuppressWarnings("unused")
|
public static long gethour(String startTime) {
|
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
long nd = 1000 * 24 * 60 * 60;// Ò»ÌìµÄºÁÃëÊý
|
long nh = 1000 * 60 * 60;// һСʱµÄºÁÃëÊý
|
long nm = 1000 * 60;// Ò»·ÖÖӵĺÁÃëÊý
|
long ns = 1000;// Ò»ÃëÖӵĺÁÃëÊý
|
long diff;
|
long day = 0;
|
long hour = 0;
|
long min = 0;
|
long second = 0;
|
long b1=0;
|
long b2=0;
|
try {
|
b1=sd.parse(GetNowTime.now()).getTime();
|
b2=sd.parse(startTime).getTime();
|
} catch (ParseException e) {
|
// TODO ×Ô¶¯Éú³ÉµÄ catch ¿é
|
e.printStackTrace();
|
}
|
|
|
// »ñµÃÁ½¸öʱ¼äµÄºÁÃëʱ¼ä²îÒì
|
diff =b1- b2;
|
// ¼ÆËã²î¶àÉÙÌì
|
//day = diff / nd;
|
// ¼ÆËã²î¶àÉÙСʱ
|
hour = diff / nh ;
|
// ¼ÆËã²î¶àÉÙ·ÖÖÓ
|
// min = diff / nm ;
|
// ¼ÆËã²î¶àÉÙÃë
|
//second = diff / ns;
|
// Êä³ö½á¹û
|
long hours=(hour - day * 24);
|
return hours;
|
|
}
|
|
|
|
}
|