First one:
+ (NSDate*)convertToUTC:(NSDate*)sourceDate
{
NSTimeZone* currentTimeZone = [NSTimeZone localTimeZone];
NSTimeZone* utcTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
NSInteger currentGMTOffset = [currentTimeZone secondsFromGMTForDate:sourceDate];
NSInteger gmtOffset = [utcTimeZone secondsFromGMTForDate:sourceDate];
NSTimeInterval gmtInterval = gmtOffset - currentGMTOffset;
return [NSDate dateWithTimeInterval:gmtInterval sinceDate:sourceDate];
}
Yes, I know this next one is strange but my server gives me a whack date format
+(NSDate *)getDateFromString:(NSString *)dtStr
{
NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[inputFormatter setLocale:locale];
[locale release];
[inputFormatter setDateFormat:@"MMMM, dd yyyy HH:mm:ss"];
NSDate *formatterDate = [[inputFormatter dateFromString:dtStr] copy];
[inputFormatter release];
return formatterDate;
}