-2

I have a GMT time downloaded from the internet that i would like to convert from the internet and display.

Currently I have a date: Sat, 16 Nov 2013 21:40:18 +0000 that i would like to convert to NSDate to then convert to my own format in an NSString.

Thanks for any help, I have been looking all of the internet for the answer.

Joiningss
  • 1,320
  • 9
  • 14
  • are you getting +0000 from nsdate? if you have offset in your date and GMT downloaded from internet then you can manage according that. – Nirav Jain Nov 17 '13 at 07:18
  • 2
    Did you have a look at the NSDateFormatter documentation and Apple's "Data Formatting Guide"? Or at the zillions date formatting questions on SO? - What did you try? – Martin R Nov 17 '13 at 07:27
  • possible duplicate of [NSDateFormatter: how to convert date string with 'GMT' to local NSDate?](http://stackoverflow.com/questions/13637298/nsdateformatter-how-to-convert-date-string-with-gmt-to-local-nsdate) – Vizllx Nov 17 '13 at 07:29

2 Answers2

0

Have a try by this code:

NSString * timeString = @"Sat, 16 Nov 2013 21:40:18 +0000";
NSString * dateFormateString = @"EEE, dd MMM yyyy HH:mm:ss ZZZ";

NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:dateFormateString];

NSDate *date = [format dateFromString:timeString];

For learn more, you should have a look about this:Date_Format_Patterns

Joiningss
  • 1,320
  • 9
  • 14
0
NSString *mygmtString = @"17/11/2013 18:14";

NSDateFormatter *mydd = [NSDateFormatter new];
[mydd setDateFormat:@"dd/MM/yyyy HH:mm"];

//Create the date string is in GMT
mydd.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
NSDate *date = [mydd dateFromString: mygmtString];

//Create a date string in the local timezone
mydd.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:[NSTimeZone localTimeZone].secondsFromGMT];
NSString *localDateString = [mydd stringFromDate:date];
NSLog(@"date = %@", localDateString)
Sport
  • 8,570
  • 6
  • 46
  • 65