package Method;
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
/**¸ÃÀàÓÃÓÚʱ¼ä¼ÆËã*/
|
public class TiemDell {
|
|
private static final String aa = "yyyy-MM-dd HH:mm:ss";
|
/**»ñÈ¡Á½¸öʱ¼äÏà²îºÁÃëÊý*/
|
public static long getTime(String oldTime,String newTime) {
|
SimpleDateFormat df = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss.SSS");
|
long NTime = 0;
|
long OTime = 0;
|
try {
|
NTime = df.parse(newTime).getTime();
|
OTime = df.parse(oldTime).getTime();
|
} catch (ParseException e) {
|
// TODO ×Ô¶¯Éú³ÉµÄ catch ¿é
|
e.printStackTrace();
|
}
|
|
long diff=(NTime-OTime);
|
return diff;
|
}
|
|
public static int getTimeDelta(Date date1,Date date2){
|
long timeDelta=(date1.getTime()-date2.getTime())/1000;//µ¥Î»ÊÇÃë
|
int secondsDelta=timeDelta>0?(int)timeDelta:(int)Math.abs(timeDelta);
|
return secondsDelta;
|
}
|
|
/**»ñÈ¡Á½¸öʱ¼äÏà²îÃëÊý*/
|
public static int getTimeDelta(String stoptime,String Startime){
|
Date date1=parseDateByPattern(stoptime, aa);
|
Date date2=parseDateByPattern(Startime, aa);
|
return getTimeDelta(date1, date2);
|
}
|
|
|
public static Date parseDateByPattern(String dateStr,String dateFormat){
|
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
|
try {
|
return sdf.parse(dateStr);
|
} catch (ParseException e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
|
}
|