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

I could use a little help please.

I am not sure how to do what it is asking. here is the question:

I modified our Movie class to have a full date for the release date instead of just the year. We want to display it in yyyy-MM-dd format, though. Add a new method to format it called getFormattedReleaseDate(), but don't add any code yet. Make it return a String and just return an empty String to start.

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

4 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Jody;

For Task 1 you just need to write the basic function structure, that returns a string, and to start with have it return an empty string.

Something along the lines of:

public String getFormattedReleaseDate () {
    return "";
}

That is the start of the date formatting challenge, Tasks 2 & 3 build upon this function layout.

Post back if you are still stuck.

Ken

ok thanks so muck that worked.

where do those lines fit on the code i am lost

try making the new code the first one, take a look at mine.

PART 2 OF THE CODE

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

noted could you please also assist with challenge 3 of 3, The mReleaseDate member variable is already stored as a Date object. Convert it and return it using the SimpleDateFormat variable.

Exavier Mugasa
Exavier Mugasa
4,088 Points

This one worked for me: import java.util.Date;

public class Movie {

private String mTitle;
private Date mReleaseDate;

public String getTitle() {
    return mTitle;
}

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

this is what i came up with and it passed

import java.util.Date;

public class Movie {

private String mTitle;
private Date mReleaseDate;
public String getFormattedReleaseDate() {
return"";

}

public String getTitle() {
    return mTitle;
}

public void setTitle(String title) {
    mTitle = title;
}

public Date getReleaseDate() {
    return mReleaseDate;
}

public void setReleaseDate(Date date) {
    mReleaseDate = date;
}

}

Andre Colares
Andre Colares
5,437 Points

Adlight Sibanda, here is the code for part 3:

public String getFormattedReleaseDate() {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    String formattedDate = formatter.format(mReleaseDate);
   return formattedDate;
}