wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Weather Underground API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Weather Underground API" Watch "Weather Underground API" New topic
Author

Weather Underground API

Steve Bradbury
Greenhorn

Joined: Jul 13, 2011
Posts: 2
Hi

I'm using the API from wunderground.com. I'm having a problem formatting the time like they've done on the homepage. He's an example: 4:58 PM BST on July 13, 2011 (GMT +0100). The time values in the XML document look like this:

<local_time>July 13, 5:00 PM BST</local_time>
<local_time_rfc822>Wed, 13 Jul 2011 16:00:56 GMT</local_time_rfc822>
<local_epoch>1310572856</local_epoch>

Basically, how would I go about formatting the time values from the XML document to make them look like this: 4:58 PM BST on July 13, 2011 (GMT +0100)? The main problem I'm having is with the GMT offset (GMT +100).

Thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

They are all the same time value, aren't they? Just represented in three different ways?

If that's the case, I would try taking the <local_epoch> value and creating a Date object from it, using the new Date(long) constructor. Then I would create a suitable SimpleDateFormat object and use that to format the Date you just created.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Steve, we don't have too many rules here, but we do ask that you BeForthrightWhenCrossPostingToOtherSites

http://www.java-forums.org/new-java/46335-wunderground-com-api-gmt-offset.html


luck, db
There are no new questions, but there may be new answers.
Steve Bradbury
Greenhorn

Joined: Jul 13, 2011
Posts: 2
Hi Paul thanks for the reply. The values are actually different <local_time> is the time of the time zone for the location and <local_time_rfc822> is the GMT offset. for Example if I did a search for Leeds, UK the local time would be BST which is (GMT +0100). If I did a search for Hollywood, FL the local time would be EDT and the GMT offset would be (GMT -0400).

I tried your suggestion using the <local_epoch> value with something like:

Format formatter = new SimpleDateFormat("hh:mm 'on' a z Z");
long timeStamp = 1247590877;
Date date = new Date(timeStamp * 1000);
System.out.println(formatter.format(date));

No matter what location I query it always returns BST +0100.

I need some way to work out the GMT offset for the local time of what ever location I query and format it like; 4:56 PM EDT on July 13, 2011 (GMT -0400).

@ Darryl sorry about the cross posting.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

That's because the time zone of your SimpleDateFormatter is what you said there. If you want the SimpleDateFormatter to display your date in some other time zone, then call its setTimeZone() method with that time zone.

Or perhaps I'm misunderstanding your requirements?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Weather Underground API
 
Similar Threads
Problems with Binding a socket on a remote machine
millenium bug returns!
DST issue with GregorianCalendar
stupid DateFormat problem
How to query?