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 Android Lists and Adapters (2015) Lists with RecyclerViews Using a Layout Manager

Josh Lloyd
Josh Lloyd
6,833 Points

Stormy AM and PM values are wrong, how do I change them?

App is working perfectly, except my PM values should be AM and vice versa. Unsure where I should change things: getHour?

public String getHour() {
    SimpleDateFormat formatter = new SimpleDateFormat("h a");
    Date date = new Date(mTime *1000);
    return formatter.format(date);
}

getTimezone isn't being used... or should I change another class even?

reply for other parts of my code, really unsure what I should put up

Dhruv Patel
Dhruv Patel
8,287 Points

If there's the problem with the location you specified for the data then it might cause a problem with the time itself.

1 Answer

Boban Talevski
Boban Talevski
24,793 Points

If you haven't figured it out yet, I think timezone should indeed be used in that method in order to get the correct time for the appropriate location. Guess Ben forgot it during the video. Without it I'm getting hours starting at 3 PM while the time at the location I'm getting the weather for is 9 PM. So if I add the line to take the timezone into account, the hours are starting at 9 PM as it should be.

public String getHour() {
        SimpleDateFormat formatter = new SimpleDateFormat("h a");
        formatter.setTimeZone(TimeZone.getTimeZone(getTimezone())); // <--- this line
        Date dateTime = new Date(getTime() * 1000);
        return formatter.format(dateTime);
    }

This is in Hour.java btw.