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

[SOLVED]The mReleaseDate member variable is already stored as a Date object. Convert it and return it using the

please help ams stuck.

Movie.java
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; 
  } 
}

Never mind.finally got it.

6 Answers

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

lol cool thanks.I marked yours as best answer its the same as what i eventually did on mine.

:-) :-)

Hey steve ,Still not working Can you help? Or just paste the code here

Hi Channon,

What's not working? Can you paste your code here as the answer is already shown above.

Steve.

I posted it steve If you didn't know

thanks Steve your answer helped me a lot.

Here'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);
  }
      }

Boom! - Thanks steve IT WORKED!!! Yeah!!

No problem! :+1: :wink:

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

All 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);
  }