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 trialMaksims Visnakovs
2,616 PointsBuild a Weather app
Stuck with Challenge 3 and 3 on Converting Date to SimpleDateFormat. Can't solve it on my own unfortunately. Would appreciate some help.
import java.util.Date;
public class Movie {
private String mTitle;
private Date mReleaseDate;
private String mGetFormattedReleaseDate;
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 formatter = new SimpleDateFormat("yyyy-MM-dd");
Date format = new SimpleDateFormat("yyyy-MM-dd");
return mSimpleDateFormat;
}
}
2 Answers
Jordan Ernst
5,121 Pointsi wasn't able to work through this project step by step but take a look at your final bit of code there. you are firstly returning something you never declared in your project. With your Date format= it appears you are repeating yourself. Remember that a good coder doesn't repeat himself. you will need to access some information from a previous method which has already gathered the information for you. you need to simply reFormat that information.
CD Lim
4,782 PointsHi there, the question said that mReleaseDate have been store to a date. Therefore, you do not need to key in
Date format = new SimpleDateFormat("yyyy-MM-dd");
you can't return mSimpleDataFormat, since you have not created that object. Here is my code:
public String getFormattedReleaseDate(){
SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd");
String dateInString = formatter.format(mReleaseDate);
return dateInString;
}
What I did was
- First, create the method
- Then create a formatter
- and then convert it to string with the mReleaseDate formatted
- Finally, return the value in string.
Jordan Ernst
5,121 PointsJordan Ernst
5,121 Pointsalso change the name of your Date variable in the getFormattedReleaseDate() method. this is a key word need when returning you value. you will need .format so change the name otherwise this will be confusing