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 trialRoshan Kashif
2,976 Pointsdate and time
It is giving me a error saying" Bummer! Make sure you use the method to format a date from the SimpleDateFormat variable."
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 String getFormattedReleaseDate() {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date mReleaseDate= new Date();
return "";
}
public void setReleaseDate(Date date) {
mReleaseDate = date;
}
}
1 Answer
Steve Hunter
57,712 PointsHi Roshan,
You've got as far as creating the formatter. You now need to use it to manipulate the content of mReleaseDate
. You've redeclared it - that's not required.
You need to use your formatter, and one of its methods, to generate a string for your method to return.
public String getFormattedReleaseDate(){
SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd");
return simpleDate.format(mReleaseDate);
}
So, the third line is where you're at - this take the formatter, uses its format
method and passes in the existing date variable. This is then returned from the function as a string.
I hope that makes sense!
Steve.
Roshan Kashif
2,976 PointsRoshan Kashif
2,976 PointsThanks a lot that worked.