IPhone: convert Nsstring to Nsdate on device time zone

I got the date from the web service, which is in GMT + 1 format (2010-02-25T20: 16: 50.387 + 05: 30). I want to convert to NSdate. I do not have a correct understanding of date formatting.

Please suggest how can I change this nsstring value to the current date format (Timezone)

+3
source share
2 answers

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

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

GMT, / GMT- , NSDate . GMT, :

NSTimeInterval timeZoneOffset = [[NSTimeZone defaultTimeZone] secondsFromGMT];
+2

NSDateFormatter - . .

+1

Source: https://habr.com/ru/post/1743770/


All Articles