Java Solution Time Subtraction problem

Source: Internet
Author: User


The result of the request is Endtime-currenttime = 1 days remaining 1 hours 10 minutes 6 seconds;

ImportJava.text.SimpleDateFormat;ImportJava.util.Calendar;Importjava.util.Date; Public classmainactivity {/*Public static void Main (string[] args) {//TODO auto-generated method stub int[] A = {1,8,2,5,4,3,6};        int[] B = Insertion.sort (A);            Print (B); } static void print (int[] arr) {for (int i=0; i<arr.length; i++) {System.out.print (arr[i]+ ""        ); }    }*/         Public Static voidMain (string[] args)throwsexception{/*Date date1 = new SimpleDateFormat ("Yyyy-mm-dd"). Parse ("2015-04-24 12:14:57");          Date date2 = new SimpleDateFormat ("Yyyy-mm-dd"). Parse ("2015-03-25 12:14:57");          Calendar cal1=calendar.getinstance ();          Calendar cal2=calendar.getinstance ();          Cal1.settime (date1);                    Cal2.settime (DATE2);          System.out.println (Date1.compareto (date2));          System.out.println (Cal1.compareto (Cal2));          String now = new SimpleDateFormat ("yyyy mm month DD Day"). Format (date1); System.out.println (now);*/SimpleDateFormat DF=NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); Java.util.Date Now= Df.parse ("2015-04-24 12:14:57"); Java.util.Date Date=df.parse ("2015-03-25 12:14:57"); LongL=now.gettime ()-Date.gettime (); Longday=l/(24*60*60*1000); LongHour= (l/(60*60*1000)-day*24); LongMin= ((l/(60*1000))-day*24*60-hour*60); LongS= (l/1000-day*24*60*60-hour*60*60-min*60); System.out.println ("+day+" Days "+hour+" hours "+min+" minutes "+s+" seconds "); }        }




Java Solution Time Subtraction problem

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.