* * Calculates the time interval, accurate to seconds, and returns a string/public string caculateduration (date begindate, date EndDate) { Long Begindatelong = Begindate.gettime ();
The date type converts to a long number of milliseconds, used to compute long Enddatelong = Enddate.gettime ();
Long Durationlong = Enddatelong-begindatelong; Long totalseconds = durationlong/1000;//Total number of seconds long secondsofday = 24 * 60 * 60;//The number of seconds in a day long Secondsofhour = 60 * 6 0; The number of seconds in an hour long secondsofminute = 60; Seconds a minute long = totalseconds/secondsofday;//Get the number of days long hours = (totalseconds% secondsofday)/secondsofhour;/ /remainder of the number of hours long minutes = ((totalseconds% secondsofday)% secondsofhour)/secondsofminute; Minutes in remainder long seconds = totalseconds% 60;//remainder return day + "days" + Hours + "hours" + minutes + "min" + seconds + "seconds"
; }
Call:
Date nowdate = new Date ()//Get current system time
date errordate = Errorrecord.geterrordate ()//Get fault occurrence time
String Duration = Otdrservice.caculateduration (errordate, nowdate)//time difference based on two dates, cumulative length