views:

409

answers:

2

hi all, I received date from Web service which is in GMT + 1 format (2010-02-25T20:16:50.387+05:30). I want to convert in NSdate. I have no proper idea about date formatter.

Please suggest that how can i Change this nsstring value to current date format (Time zone)

+1  A: 

NSDateFormatter is all about converting dates to and from string representations. Take a look at the docs for that.

Chuck
+1  A: 

Convert "2010-02-25T20:16" into NSDate using DateFormatter:

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyyMMdd'T'HHmm";
NSDate *gmtDate = [formatter dateFromString:@"2010-02-25T20:16"];

Once you have the GMT date, you can add/substract the GMT-your time zone offset to it to get the current NSDate in your time zone. To get the offset between your timezone and GMT, you can use the following:

NSTimeInterval timeZoneOffset = [[NSTimeZone defaultTimeZone] secondsFromGMT];
Hetal Vora