-4

I am wondering if there are a simple way of getting the time for a given city. For example I want to know what time is it in NYC. I have lat/lon in my data so I could use this information.

dandan78
  • 13,328
  • 13
  • 64
  • 78
Alejandro Luengo
  • 1,256
  • 1
  • 17
  • 27
  • Alejandro, do you want to do this via a remote API (coordinates to time) or a local database of city coordinates, which derive a time offset from which the time can be calculated using your local machine clock? – halfer Jan 30 '13 at 15:02
  • Also: http://stackoverflow.com/questions/7651845/how-to-get-the-date-time-for-a-particular-city-in-c – halfer Jan 30 '13 at 15:05
  • Also: http://stackoverflow.com/questions/55901/web-service-current-time-zone-for-a-city – halfer Jan 30 '13 at 15:06
  • Thanks for the response halfer. I found a webservice in your links that will make the trick. I still belive this question is important and there is no response for that in objective-C so I will answer the question as soon as I code it. – Alejandro Luengo Jan 30 '13 at 15:52
  • No worries, pleased you got a solution: +1. By the way if you want to ping someone, say @halfer - otherwise a notification isn't received. – halfer Jan 31 '13 at 10:13

1 Answers1

1

Here is my answer, using 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];

}

You must provide lat & lon for the city. TBXML class from Tom Bradley http://www.tbxml.co.uk/TBXML/TBXML_Free.html

Alejandro Luengo
  • 1,256
  • 1
  • 17
  • 27