Advertisement
vergepuppeter

Joda Sample

Dec 1st, 2014
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. package joda;
  2.  
  3. import org.joda.time.DateTime;
  4. import org.joda.time.Period;
  5. import org.joda.time.PeriodType;
  6.  
  7. /**
  8. *
  9. * @author Kaede
  10. */
  11. public class Joda {
  12.  
  13. /**
  14. * @param args the command line arguments
  15. */
  16. public static void main(String[] args) {
  17. // TODO code application logic here
  18. DateTime date1 = new DateTime(2013, 1, 1, 0, 0, 0, 0);
  19. DateTime date2 = new DateTime(2014, 5, 22, 0, 0, 0, 0);
  20.  
  21. System.out.println(calYearMonthDays(date1, date2));
  22.  
  23. }
  24.  
  25. public static String calYearMonthDays(DateTime date1, DateTime date2)
  26. {
  27. Period totDays = new Period(date1, date2, PeriodType.yearMonthDayTime());
  28. return "Years: "+totDays.getYears()+"\nMonth: "+totDays.getMonths()+"\nDays: "+totDays.getDays();
  29. }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement