Using date attribute from an AGSGraphic's attributes

605
4
Jump to solution
03-14-2012 01:01 PM
TJMott
by
New Contributor II
I have an AGSGraphic that was returned from an AGSQueryTask. I want to do some custom formatting to the attributes before displaying them to the user. I have an attribute that I know is a valid date by checking the feature in ArcGIS Server's REST page for the feature class, but I'm not sure what the value I'm actually getting is. I tried casting it to an NSDate pointer and got a bad object. What do I need to do to this value to get a valid NSDate from it?
0 Kudos
1 Solution

Accepted Solutions
TJMott
by
New Contributor II
I just figured it out. I can take the value, divide by 1000, then convert it to a float (checking in the debugger proves that NSDate treats 1253577600.0 differently than 1253577600), then pass it as a parameter to NSDate dateWithTimeIntervalSince1970, and it works.

View solution in original post

0 Kudos
4 Replies
NimeshJarecha
Esri Regular Contributor
The attribute is nothing but a string. If it's a valid date string then you can convert it into NSDate with following code.

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc]init]autorelease];
//if you want to set any time zoneand date format
//[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
//[dateFormatter setDateFormat:@"MM/dd/yyyy hh:mma"];
NSDate *date = [dateFormatter dateFromString:dateStringAttribute];
NSLog(@"date: %@",date);

Regards,
Nimesh
0 Kudos
TJMott
by
New Contributor II
The value for the attribute, from what I can tell in the debugger, is a long with value 1253577600000. On the ArcGIS Server REST page for the same feature and attribute, it displays 2009/09/22 00:00:00 UTC.
0 Kudos
TJMott
by
New Contributor II
I just figured it out. I can take the value, divide by 1000, then convert it to a float (checking in the debugger proves that NSDate treats 1253577600.0 differently than 1253577600), then pass it as a parameter to NSDate dateWithTimeIntervalSince1970, and it works.
0 Kudos
NimeshJarecha
Esri Regular Contributor
I was about to suggest that only....good to know that you figured out! 🙂

Regards,
Nimesh
0 Kudos