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 trialRicky Sparks
22,249 PointsIn your new method, add a SimpleDateFormat variable. Use "yyyy-MM-dd" for the format parameter of the constructor.
Not sure what's wrong with my code?
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 "";
simpleDateFormat = "yyyy-MM-dd";
}
}
5 Answers
James Simshaw
28,738 PointsThis likely won't be the complete answer to your question, but you have a return statement before some other commands which I assume you want to run in your getFormattedReleaseDate function. However, once you hit the return call, your function returns that value and leaves the function.
Ben Wong
19,426 Pointspublic String getFormattedReleaseDate () { return ""; SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
} }
What's wrong with my answer? Thanks:)
Ben Wong
19,426 Pointsnvm. I got it putting the return statement below the variable declaration statement.
Thanks!
MUZ140741 Valentine Makuyana
4,136 PointsHi Ben,
After reading the answers posted above I still can't seem to get the code correct. If you could post the code exactly as it would appear...
Thanks
Andrew Polania
5,371 PointsJust try to put the line, between , import java.util.Date;
public class Movie { public String getFormattedReleaseDate() { return ""; } SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Just Similar to the video like =
public String getFormattedTime(){ SimpleDateFormat formatter = new SimpleDateFormat("h:mm a"); formatter.setTimeZone(TimeZone.getTimeZone(getTimezone())); Date dateTime = new Date(getmTime()* 1000); String timeString = formatter.format(dateTime);
return timeString;
so the answer will be
import java.util.Date;
public class Movie { public String getFormattedReleaseDate() { return ""; } SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
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;
}
}
Gregory Whitaker
8,220 PointsThanks Andrew.
This works:
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 "";
}
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
}
Ricky Sparks
22,249 PointsRicky Sparks
22,249 PointsThanks I figured it out :D