cocoa - Time Zone conversion form stringdate -


I have stringdate 16-May-2010 23:04:44 which I need to convert to GMT time zones 17-May-2010 is 12:03:03.

I used the date formats to convert but the format I am getting is not necessary. I am sending the code, please let me know whether I am correcting or not

Here is the code:

  NSString * timeStamp = [format stringFromDate: [NSDate date ]]; NSString * Output = [TimeConnect DatestringForm: Timestamp]; - (NSString *) dateStringFromString: (NSString *) Source string {NSDateFormatter * dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [DateFormatter setFormatterBehavior: NSDateFormatterBehavior10_4]; [DateFormatter setDateFormat: @ "DD-MMMM-YYYY HH: MM: SS"]; Nstmezone * GMT = [Nstimeon TimezoneWithAbet: @ "GMT"]; [DateTimeSetimezone: GMT]; NSDate * date = [dateFormatter dateFromString: sourceString]; Return [dateFormatter stringFromDate: date]; }  

The one I got is the same old time without conversion. So please tell me the correct solution.

I do not have any coca, but if I understand correctly your code, Never tell that your original string is not GMT but GMT-1.

Based on your code (and again, without the knowledge of cocoa), I believe what you have to do:

  NSTimeZone * gmtminusone = [NSTimeZone timeZoneForSecondsFromGMT : -3600.0]; [Dateformer settimeogon: GMTminuson]; NSDate * date = [dateFormatter dateFromString: sourceString]; Nstmezone * GMT = [Nstimeon TimezoneWithAbet: @ "GMT"]; [DateTimeSetimezone: GMT]; Return [dateFormatter stringFromDate: date];  

If it does not work immediately, you probably have to do it:

  1. Set the string with the date format GMT - 1, to output to a date.
  2. For a string output, parse date formatter set for GMT.

Comments