有没有办法为某个城市腾出时间?

时间:2013-01-30 12:51:41

标签: ios cocoa

我想知道是否有一种简单的方法来获得某个城市的时间。例如,我想知道纽约市的时间。我的数据中有lat / lon所以我可以使用这些信息。

1 个答案:

答案 0 :(得分:1)

这是我的回答,使用halfer tips

- (void)getWorldClock:(float)lat:(float)lon
{
    NSString *thisWorldTime = [[NSString alloc]init];

    NSString *urldata=[[NSString alloc]initWithFormat:@"http://www.earthtools.org/timezone-1.1/%f/%f", lat, lon];

    NSString *encoding = [urldata stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSLog(@"URL :%@",encoding);

    TBXML *tbxml =[TBXML tbxmlWithURL:[NSURL URLWithString:encoding]];
    TBXMLElement *root = tbxml.rootXMLElement;

    if (root) {
        TBXMLElement *isoTime = [TBXML childElementNamed:@"isotime" parentElement:root];
        NSLog(@"Time in %f %f is %@", lat, lon, [TBXML textForElement:isoTime]);        
    }

    [thisWorldTime release];

}

你必须提供lat&这个城市。来自Tom Bradley的TBXML课程http://www.tbxml.co.uk/TBXML/TBXML_Free.html

相关问题