Calculates the time difference between two dates, cumulative length, accurate to seconds __ notes

Source: Internet
Author: User
Tags time interval
 * * 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.