ios - How to convert mail server date string to nsdate -
i getting date string form mail server this. thu, 31 dec 2009 14:32:15 +0580.
want convert date string date.
here's code:
- (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. nsstring *inputstring=@"mon, 3 sep 2012 08:32:39 +0580"; nsdateformatter *dateformatter = [[nsdateformatter alloc] init]; [dateformatter setdateformat:@"eee, dd mmm yyyy hh:mm:ss zzz"]; [dateformatter setlenient:yes]; nslocale *enus = [[nslocale alloc]initwithlocaleidentifier:@"en_us"]; [dateformatter setlocale:enus]; nsdate *result = [dateformatter datefromstring:inputstring]; nslog(@"test==%@",result); }
i getting output null.
excepted output : 2012-09-03 03:02:39 +0000
first problem: not trying read "tue" on string. (add "eee, " front of format)
second , bigger problem: +0580 not valid time zone. there php bug few years ago mistakenly returned ist (+0530) +0580. +0580 makes no sense. means 5 hours , 80 minutes. can 1 of 2 things: either replace +0580 +0530 before process or set date formatter time zone ist , remove +0580 string.
i see accepted answer, answer "works" because fails parse final part , ignores time zone. ran , got 2013-07-09 08:32:38 +0000 (which not same 2013-07-09 08:32:39 +0580)
removing +
in accepted answer's format causes formatter parse correctly, null
because timezone invalid. changing time zone +0530 gives expected result of 2013-07-09 03:02:39 +0000
Comments
Post a Comment