Friday, February 22, 2019

 //Program to calculate number of days between 2 dates
 
import java.util.Date;
import java.text.SimpleDateFormat;
class Example 
{
   public static void main(String args[])
   {
  SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy");
  String d1 = "01 01 2018";
  String d2 = "22 02 2019";

  try {
        Date dateBefore = myFormat.parse(dateBeforeString);
        Date dateAfter = myFormat.parse(dateAfterString);
        long difference = dateAfter.getTime() - dateBefore.getTime();
        float daysBetween = (difference / (1000*60*60*24));
               System.out.println("Number of Days between dates: "+daysBetween);
      }  
        catch (IOException e) 
         {
        System.out.println("Invalid");
  }
   }
}

5 comments:

  1. Thank you sir...i am arunabha pal of 8b thank u for doing the given programe thanks for the help before exam.

    ReplyDelete
  2. Thanks Sir for the post
    All clear before exams!

    ReplyDelete
  3. Sir I am Swagata Ganguly Of Class VIII C .
    I cant understand what to do in prog.9 .

    ReplyDelete
  4. Sir i am debadree Sekhar das of class VIII C ....I am having problem to do program 10

    ReplyDelete

  3.WAP IN JAVA TO INPUT THREE NUMBERS AND COUNT HOW MANY OF THEM ARE EVEN .   import java.util.*; class Prog {   public static ...