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

Charles Romeo
Charles Romeo
1,042 Points

Date Formatter/ getTimeZone() not working correctly?

I have manually changed the longitude and latitude to reflect my current city. Everyone is coming in from forecast.io just perfectly. Yet, my time is very very off. It is currently 2:00pm where I am. The app claims it is 8:00pm. Sometimes it is closer, sometimes it is further. Just a little bit ago it said it was 4:12am. Yet it was 1:30 something. Where in the world is it 4:12 when it is 1:30 here? That is impossible (if you understand what I am trying to say there).

I have tripled checked everything code wise. I am brand new to this stuff. Any help?

Ben said in the video he saw the getTimeZone in main activity, but where? Please help me figure this out. It is my last step.

my code is as follows...

public String getFormattedTime() { SimpleDateFormat formatter = new SimpleDateFormat("h:mm a"); formatter.setTimeZone(TimeZone.getTimeZone(getTimeZone())); Date dateTime = new Date(getTime() * 1000); String timeString = formatter.format(dateTime);

return timeString; }

Charles Romeo
Charles Romeo
1,042 Points

Just figured out that I am currently under GMT. For now at least.

Charles Romeo
Charles Romeo
1,042 Points

LogCat claims i am under the America/Chicago timezone (which is correct) and is offset by -6 hours. Again. correct. Yet my time doesn't show up correctly?.

1 Answer

Jordan Ernst
Jordan Ernst
5,121 Points

can you upload your code so i can see your work?