나는 PHP에서이 timeDiff 기능이 있습니다PHP timeDiff 코드를 Android에 어떻게 변환합니까?
PHP 코드 :
function timeDiff($firstTime,$lastTime){
// convert to unix timestamps
$firstTime=strtotime($firstTime);
$lastTime=strtotime($lastTime);
// perform subtraction to get the difference (in seconds) between times
$timeDiff=$lastTime-$firstTime;
// return the difference
return $timeDiff;
}
가 지금은 안드로이드 위의 기능을 사용하려면, 그래서 다음과 같이 코드 :
안드로이드 코드 :
private double timeDiff(String startTime, String endTime){
try {
SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date startTime_d = (Date) parser.parse(formater.format(startTime));
Date endTime_d = (Date) parser.parse(formater.format(startTime));
double dateDiff = startTime_d.getTime() - endTime_d.getTime();
return dateDiff;
}catch(ParseException e){
// TODO Auto-generated catch block
e.printStackTrace();
}catch(NullPointerException e){
Log.e(LOG_TAG, e.toString());
}
return 0;
}
하지만 logcat에는 java.lang.IllegalArgumentException이 표시됩니다.
나는 초보자 인 프로그래머에게 감사드립니다. : 당신이 다음과 같이 밀리 초 단위로 차이를 계산할 수 날짜에 차이하려는 경우 Date objects의 getTime()
방법으로