Calculation:
How many days are there in the middle of 2012-3-17 "2012-4-6"?
Import Java.text.dateformat;import Java.text.parseexception;import Java.text.simpledateformat;import Java.util.date;public class DateDemos2 {//Practice://"2012-3-17" to "2012-4-6" how many days in between? /** writing ideas 1. Converts a date-formatted string into a Date object. 2. Turn the date object into a millisecond value. 3. Subtract, programming days. * @throws Exception */public static void Main (string[] args) throws Exception {//TODO auto-generated method stubstring S1 = "2012-3-17"; String s2 = "2012-4-6";//Call Custom Party Datetodemos (S1,S2);} private static void Datetodemos (string s1, string s2) throws Exception {//convert date in string to date format DateFormat df = Dateformat.get Dateinstance ();//Format Date Object df = new SimpleDateFormat ("Yyyy-mm-dd");//Converts a date in a string to a date in a Date object date date1 = Df.parse (S1);D Ate date2 = df.parse (s2);//Gets the time millisecond value corresponding to the corresponding date long time1 = Date1.gettime (); Long time2 = Date2.gettime (); Long times = Math.Abs (t IME2-TIME1); System.out.println (times); int day = GetDay (times); System.out.println (s1+ "and" +s2+ "Difference:" +day+ "Day");} private static int GetDay (long times) {//TODO auto-generated method Stubreturn (int) (TimeS/1000/60/60/24);}}
To run the program:
Dark Horse Programmer-Calculation: 2012-3-17 "to" 2012-4-6 "how many days in between?