-
-
Save Kevinwlee/1958498 to your computer and use it in GitHub Desktop.
Getting Date/Time from .NET api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSDate*) getDateFromJSON:(NSString *)dateString { | |
// Expect date in this format "/Date(1268123281843)/" | |
int startPos = [dateString rangeOfString:@"("].location+1; | |
int endPos = [dateString rangeOfString:@")"].location; | |
NSRange range = NSMakeRange(startPos,endPos-startPos); | |
unsigned long long milliseconds = [[dateString substringWithRange:range] longLongValue]; | |
NSLog(@"%llu",milliseconds); | |
NSTimeInterval interval = milliseconds/1000; | |
return [NSDate dateWithTimeIntervalSince1970:interval]; | |
} | |
- (NSString *)startAndEndTimeText { | |
NSString *startTime = [self.truck objectForKey:@"StartTime"]; | |
NSString *endTime = [self.truck objectForKey:@"EndTime"]; | |
NSDate *startDate = [self getDateFromJSON:startTime]; | |
NSDate *endDate = [self getDateFromJSON:endTime]; | |
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | |
[dateFormatter setDateFormat:@"h:mm a"]; | |
return [NSString stringWithFormat:@"%@ - %@", [dateFormatter stringFromDate:startDate], [dateFormatter stringFromDate:endDate]]; | |
} | |
//It will look something like this: | |
// 9:00 AM - 3:00 PM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Latitude": 31.550837, | |
"Longitude": -97.116265, | |
"Description": "Drop dirties by 1pm in the laundry cart near front desk.", | |
"Weekday": 3, | |
"StartTime": "/Date(1329535556148)/", | |
"EndTime": "/Date(1329535556148)/", | |
"Dorms": [ | |
"South Russell" | |
], | |
"Color": null, | |
"IsLobby": true, | |
"Icon": "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment