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 trialDerrick Shepherd
4,861 PointsOk, I've Made Several Attempts At This, watched the video five times and still can't figure out how to convert the date.
Please Help :(
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 format = new SimpleDateFormat("yyyy-MM-dd");
formatter.setReleaseDate(ReleaseDate.getReleaseDate());
Date date = new Date(getDate());
String dateTime = formatter.format(date);
return dateTime;
}
public void setReleaseDate(Date date) {
mReleaseDate = date;
}
}
3 Answers
Steve Hunter
57,712 PointsHi Derrick,
You've made the method, getFormattedReleaseDate
, now that needs to amend the mReleaseDate
member variable.
First, set up a formatter, as you have done correctly:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Then, use it on the mReleaseDate
variable (and you might as well return that at the same time):
return format.format(mReleaseDate);
And that's it!
public String getFormattedReleaseDate(){
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
return format.format(mReleaseDate);
}
I hope that helps.
Steve.
Steve Hunter
57,712 PointsIf you called your formatter something like dateFormatter
or simpleFormatter
that might be a little clearer. But that's being picky.
public String getFormattedReleaseDate(){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
return simpleDateFormat.format(mReleaseDate);
}
Derrick Shepherd
4,861 PointsThank You So Much Steve! It seems like once again I was overthinking the code challenge.
Steve Hunter
57,712 PointsNo problem! It is easy to overthink them sometimes. I guess if you try to think in language terms of what you're trying to achieve, and what you're working with, that might make the goal a little clearer?
So, for this one, the sentence, "I am writing a method called getFormattedReleaseDate
that uses a SimpleDateFormat
to convert mReleaseDate
and return the formatted result" might make it clear that there's nothing else in scope here.
With all problems, defining what the problem/solution relationship is first always helps. Your last step is reaching for code - the solution is never in the compiler!!
Derrick Shepherd
4,861 PointsThat's A great way to look at it Steve! I will use that mode of thinking in the upcoming code challenges. Thanks again
Derrick Shepherd
4,861 PointsDerrick Shepherd
4,861 PointsThis Is The Question In This Code Challenge: "The mReleaseDate member variable is already stored as a Date object. Convert it and return it using the SimpleDateFormat variable."