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 trial

Android Build a Weather App (2015) Working with JSON Formatting a Date

Maksims Visnakovs
Maksims Visnakovs
2,616 Points

Build 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.

Movie.java
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
Jordan Ernst
5,121 Points

i 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.

Jordan Ernst
Jordan Ernst
5,121 Points

also 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

CD Lim
CD Lim
4,782 Points

Hi 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

  1. First, create the method
  2. Then create a formatter
  3. and then convert it to string with the mReleaseDate formatted
  4. Finally, return the value in string.