fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import org.joda.time.LocalDateTime;
  7. import org.joda.time.Period;
  8. import org.joda.time.PeriodType;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main(String[] args) {
  14. //creation of calendar object to call the method
  15. //new GregorianCalendar(yyyy, mm, dd) here month 0 is for January
  16. SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
  17.  
  18. Date convertedDateA;
  19. Date convertedDateB;
  20.  
  21. convertedDateA = dateFormat.parse("31/02/2001");
  22. cal.setTime(convertedDateA);
  23. timeInMillA = cal.getTimeInMillis();
  24.  
  25.  
  26. convertedDateB = dateFormat.parse("01/03/2001");
  27. cal.setTime(convertedDateB);
  28. timeInMillB = cal.getTimeInMillis();
  29. LocalDateTime startA = new LocalDateTime(timeInMillA);
  30. LocalDateTime startB = new LocalDateTime(timeInMillB);
  31.  
  32. Period difference = new Period(startA, startB, PeriodType.days());
  33. int day = difference.getDays();
  34.  
  35. difference = new Period(startA, startB, PeriodType.months());
  36. int month = difference.getMonths();
  37. System.out.println("Number of months between two date is "+day);
  38. System.out.println("Number of months between two date is "+month);
  39. }
  40.  
  41.  
  42.  
  43.  
  44. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:6: error: package org.joda.time does not exist
import org.joda.time.LocalDateTime;
                    ^
Main.java:7: error: package org.joda.time does not exist
import org.joda.time.Period;
                    ^
Main.java:8: error: package org.joda.time does not exist
import org.joda.time.PeriodType;
                    ^
Main.java:16: error: cannot find symbol
        SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); 
        ^
  symbol:   class SimpleDateFormat
  location: class Ideone
Main.java:16: error: cannot find symbol
        SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); 
                                          ^
  symbol:   class SimpleDateFormat
  location: class Ideone
Main.java:22: error: cannot find symbol
    cal.setTime(convertedDateA);
    ^
  symbol:   variable cal
  location: class Ideone
Main.java:23: error: cannot find symbol
    timeInMillA = cal.getTimeInMillis();
    ^
  symbol:   variable timeInMillA
  location: class Ideone
Main.java:23: error: cannot find symbol
    timeInMillA = cal.getTimeInMillis();
                  ^
  symbol:   variable cal
  location: class Ideone
Main.java:27: error: cannot find symbol
    cal.setTime(convertedDateB);
    ^
  symbol:   variable cal
  location: class Ideone
Main.java:28: error: cannot find symbol
    timeInMillB = cal.getTimeInMillis();
    ^
  symbol:   variable timeInMillB
  location: class Ideone
Main.java:28: error: cannot find symbol
    timeInMillB = cal.getTimeInMillis();
                  ^
  symbol:   variable cal
  location: class Ideone
Main.java:29: error: cannot find symbol
        LocalDateTime startA = new LocalDateTime(timeInMillA);
        ^
  symbol:   class LocalDateTime
  location: class Ideone
Main.java:29: error: cannot find symbol
        LocalDateTime startA = new LocalDateTime(timeInMillA);
                                   ^
  symbol:   class LocalDateTime
  location: class Ideone
Main.java:29: error: cannot find symbol
        LocalDateTime startA = new LocalDateTime(timeInMillA);
                                                 ^
  symbol:   variable timeInMillA
  location: class Ideone
Main.java:30: error: cannot find symbol
    LocalDateTime startB = new LocalDateTime(timeInMillB);
    ^
  symbol:   class LocalDateTime
  location: class Ideone
Main.java:30: error: cannot find symbol
    LocalDateTime startB = new LocalDateTime(timeInMillB);
                               ^
  symbol:   class LocalDateTime
  location: class Ideone
Main.java:30: error: cannot find symbol
    LocalDateTime startB = new LocalDateTime(timeInMillB);
                                             ^
  symbol:   variable timeInMillB
  location: class Ideone
Main.java:32: error: cannot find symbol
    Period difference = new Period(startA, startB, PeriodType.days());
    ^
  symbol:   class Period
  location: class Ideone
Main.java:32: error: cannot find symbol
    Period difference = new Period(startA, startB, PeriodType.days());
                            ^
  symbol:   class Period
  location: class Ideone
Main.java:32: error: cannot find symbol
    Period difference = new Period(startA, startB, PeriodType.days());
                                                   ^
  symbol:   variable PeriodType
  location: class Ideone
Main.java:35: error: cannot find symbol
    difference = new Period(startA, startB, PeriodType.months());
                     ^
  symbol:   class Period
  location: class Ideone
Main.java:35: error: cannot find symbol
    difference = new Period(startA, startB, PeriodType.months());
                                            ^
  symbol:   variable PeriodType
  location: class Ideone
22 errors
stdout
Standard output is empty