I have a class Movie
in it i have a start Date, a duration and a stop Date.
Start and stop Date are Date Objects (private Date startDate …)
(It’s an assignment so i cant change that)
now I want to automatically calculate the stopDate by adding the duration (in min) to the startDate.
By my knowledge working with the time manipulating functions of Date is deprecated hence bad practice but on the other side i see no way to convert the Date object to a calendar object in order to manipulate the time and reconvert it to a Date object.
Is there a way? And if there is what would be best practice
What you could do is creating an instance of a
GregorianCalendarand then set theDateas a start time:However, another approach is to not use
Dateat all. You could use an approach like this:In this way you can access both the start time and get the duration from start to stop. The precision is up to you of course.