import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Test {
/**
* 获取给定时间与当前系统时间的差值(以毫秒为单位)
*
* @author GaoHuanjie
*/
public long getTimeDifferenceBetweenSystemTimeAndParamTime(String paramTime) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String systemTime = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss").format(new Date().getTime());// 获取系统时间
long difference = 0;
try {
Date systemDate = dateFormat.parse(systemTime);
Date paramDate = dateFormat.parse(paramTime);
difference = systemDate.getTime() - paramDate.getTime();
System.out.println("系统时间:" + systemTime + ",给定时间:" + paramTime + ",给定时间与当前系统时间的差值(以毫秒为单位):" + difference + "毫秒");
} catch (Exception e) {
e.printStackTrace();
}
return difference;
}
public static void main(String[] args) {
new Test().getTimeDifferenceBetweenSystemTimeAndParamTime("2014-06-04 14:48:47");
}
}