import java.io.*; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.text.SimpleDateFormat; public class DureeConsultPage { public static void main(String[] args) { String fileName="OrdSessionTpsDeclenchement.txt",line; BufferedReader reader = null; SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss"); try { File file = new File(fileName); reader = new BufferedReader(new FileReader(file)); while ((line = reader.readLine()) != null) { String []tmp = line.split(";"); String date=tmp[2]; String userCourant=tmp[0]; Date heureFinSession=new Date(),heureDebSession=new Date(); try{ heureDebSession=sdf.parse(tmp[3]); }catch(Exception exc){} String page=tmp[1]; long dureeConsultPage=0; String Line; while((Line=reader.readLine())!=null && userCourant.compareTo(Line.split(";")[0])==0 && date.compareTo(Line.split(";")[2])==0){ try{ heureFinSession=sdf.parse(Line.split(";")[3]); }catch(Exception exc){} //dureeConsulPage=Math.abs(heureFinSession.getTime()-heureDebSession.getTime())/(1000*60); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(heureFinSession); int Hfin = cal.get(Calendar.HOUR); int MinFin = cal.get(Calendar.MINUTE); cal.setTime(heureDebSession); int HDebut = cal.get(Calendar.HOUR); int MinDebut = cal.get(Calendar.MINUTE); // conversion heures minutes => minutes int mTotal1 = Hfin*60+MinFin; int mTotal2 = HDebut*60+MinDebut; // calcul de l'écart en minutes dureeConsultPage = mTotal1-mTotal2; } try{ String chemin="DureeConsulPage.txt"; //c ici BufferedWriter bw=null; if(!(new File(chemin)).exists()) bw=new BufferedWriter(new FileWriter(chemin)); else{ bw=new BufferedWriter(new FileWriter(chemin,true)); bw.write(date+";"+userCourant+";"+page+";"+dureeConsultPage); bw.write("\n"); } bw.close(); }catch(IOException exc){} } } catch (IOException e) { e.printStackTrace(); } finally { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } }