0

I get the date from URL as GMT Format as follows.

Thu, 13 Nov 2010 05:15:01 GMT

I want to display that date as ordinary format.

I used the following code.

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH':'mm':'ss"];
NSDate *date = [dateFormatter dateFromString:@"Thu, 13 Nov 2010 05:15:01"];
NSString *strDate = [dateFormatter stringFromDate:date];    //[NSDate date]];   // Ordinary Format
NSLog(@"Date is ........ %@", strDate);
[dateFormatter release];

This above code display the following output.


Date is ........ Sat, 13 Nov 2010 05:15:01

But when I put the date as follow the date "Thu, 13 Nov 2010 05:15:01 GMT" in NSDate then the out put is display as NULL.

How I will edit this

    [dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH':'mm':'ss"]; 

to this date "Thu, 13 Nov 2010 05:15:01 GMT"

halfer
  • 19,824
  • 17
  • 99
  • 186
Velmurugan
  • 2,303
  • 6
  • 30
  • 45

1 Answers1

1

Can't you simply remove the GMT substring from your string and call the dateFromString: on the resulting string?

rano
  • 5,616
  • 4
  • 40
  • 66
  • if i remove GMT using remove method, then how it will change our local time? Since it have 5 hours 30 minutes difference. [5.30 hours difference]. So i cant remove the GMT text using substring. So i need Date formats. – Velmurugan Nov 13 '10 at 12:33
  • You can remove GMT, then load it into an NSDate object and then convert it to your local time. Have a look at this answer http://stackoverflow.com/questions/1081647/how-to-convert-time-to-the-timezone-of-the-iphone-device/1082179#1082179 – rano Nov 13 '10 at 12:38
  • Instead of "removing", why not escaping it: `@"EEE, dd MMM yyyy HH':'mm':'ss 'GMT'"`? – Larme Dec 07 '17 at 19:25