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

Ricky Sparks
Ricky Sparks
22,249 Points

In 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?

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() {
    return "";
    simpleDateFormat = "yyyy-MM-dd";
  }
}

5 Answers

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

Ricky Sparks
Ricky Sparks
22,249 Points

Thanks I figured it out :D

Ben Wong
Ben Wong
19,426 Points

public String getFormattedReleaseDate () { return ""; SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

} }

What's wrong with my answer? Thanks:)

Ben Wong
Ben Wong
19,426 Points

nvm. I got it putting the return statement below the variable declaration statement.

Thanks!

Hi 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
Andrew Polania
5,371 Points

Just 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;

}

}

Thanks 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");

}