0

The Day class knows about the intricacies of our calendar, such as the fact that January has 31 days and February has 28 or sometimes 29.

I am trying to implement this public class into my program however I am unable to, I am making a program that calculates how many days a person has been alive for

This is the code given within the textbook:

public class DaysAlivePrinter 
    public static void main(String[] args){
       Day jamesGoslingsBirthday = new Day(1955, 5, 19);
       Day today = new Day();
       System.out.print("Today: ");
       System.out.println(today.toString());
       int daysAlive = today.daysFrom(jamesGoslingsBirthday);
       System.out.print("Days alive: ");
       System.out.println(daysAlive);
  }
}

I mostly understand the JavaDoc - http://www.jfree.org/jfreechart/api/javadoc/org/jfree/data/time/Day.html - but nowhere does it say how to import the functionality of the Day class into your program. What is the process to do this?

CJ Carter
  • 27
  • 8
  • 1
    I would *strongly* recommend using either `java.time` if you're using Java 8, or [Joda Time](http://joda.org/joda-time) for this, rather than part of a random charting API. – Jon Skeet Feb 28 '15 at 11:29
  • You might want to use `joda time` and the answer from this Stack Overflow question: http://stackoverflow.com/questions/3802893/number-of-days-between-two-dates-in-joda-time – Marvin Feb 28 '15 at 11:29
  • Are you asking how to use an `import` statement? – Dawood ibn Kareem Feb 28 '15 at 12:57

1 Answers1

1

Why not simply use the java time api (Java 8):

LocalDate jamesGoslingsBirthday = LocalDate.of(1955, 5, 19);
LocalDate today = LocalDate.now();
System.out.println("Today: " + today);
int daysAlive = ChronoUnit.DAYS.between(jamesGoslingsBirthday, today);
assylias
  • 321,522
  • 82
  • 660
  • 783