Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMUZ140584 Heredity Mbundire
4,979 PointsI modified our Movie class to have a full date for the release date instead of just the year. We want to display it in y
import java.util.Date;
public class Movie {
private String mTitle;
private Date mReleaseDate;
public String getTitle() {
return mTitle;
}
public void setTitle(String title) {
mTitle = title;
}
public Date getReleaseDate() {
return mReleaseDate;
}
public void setReleaseDate(Date date) {
mReleaseDate = date;
public String getFormattedReleaseDate () {
return "";
}
}
1 Answer
Steve Hunter
57,712 PointsHiya,
First, you need to implement the method outline, as you have done.
Next, you need to create a new variable of type SimpleDateFormat
- I've called it simpleDate
. The public constructor for this class takes a string format as a parameter. The documentation shows you all the possible formats, but the question helpfully tells you what to use.
The next line uses the format
method of the SimpleDateFormat
class and passes in a Date
parameter. That converst the date to a string.
That string is then returned from the method.
Hope that helps.
public String getFormattedReleaseDate() {
SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd");
simpleDate.format(mReleaseDate);
return simpleDate;
}
Steve.