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 trialMUZ140564 Kudakwashe Jena
4,895 Points[SOLVED]The mReleaseDate member variable is already stored as a Date object. Convert it and return it using the
please help ams stuck.
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() {
SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd");
simpleDate.format(mReleaseDate);
return simpleDate;
}
}
6 Answers
Steve Hunter
57,712 PointsYou got it ... awesome! My code looked like:
public String getFormattedReleaseDate() {
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
return dateFormatter.format(mReleaseDate);
}
I'll mark the post as solved.
Steve.
MUZ140564 Kudakwashe Jena
4,895 Pointslol cool thanks.I marked yours as best answer its the same as what i eventually did on mine.
Steve Hunter
57,712 Points:-) :-)
channonhall
12,247 PointsHey steve ,Still not working Can you help? Or just paste the code here
Steve Hunter
57,712 PointsHi Channon,
What's not working? Can you paste your code here as the answer is already shown above.
Steve.
channonhall
12,247 PointsI posted it steve If you didn't know
MUZ140567 Merceline Nhamo
4,739 Pointsthanks Steve your answer helped me a lot.
channonhall
12,247 PointsHere's my code :
mport 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() {
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
return dateFormatter.format(mReleaseDate);
}
}
channonhall
12,247 PointsBoom! - Thanks steve IT WORKED!!! Yeah!!
Steve Hunter
57,712 PointsNo problem!
Steve Hunter
57,712 PointsOK - the new method needs to be called getFormattedReleaseDate()
, it returns a string and takes no parameters. The first task wants the method to return an empty string. That would look like:
public String getFormattedReleaseDate(){
return "";
}
Next, you want to add a date formatter with the given format. That line is:
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
You then pass the member variable mReleaseDate
into the formatter using the format
method and return the result of that, replacing your existing return line. That line looks like:
return dateFormatter.format(mReleaseDate);
Put that all together and you end up with the method marked as Best Answer in here.
Steve.
Steve Hunter
57,712 PointsAll you did wrong was putting the new method inside the setReleaseDate
method. If you move the curly braces around so that your new method is outside that, it would work.
public void setReleaseDate(Date date) {
mReleaseDate = date;
// move out of here
} // <-- to after this brace
public String getFormattedReleaseDate() {
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
return dateFormatter.format(mReleaseDate);
}
MUZ140564 Kudakwashe Jena
4,895 PointsMUZ140564 Kudakwashe Jena
4,895 PointsNever mind.finally got it.