ios - NSDate different in simulator and device(ipad) -


hi converting gmt time local time in project - getting correct value in simulator , in iphone/ipod - when run in ipad getting null, here code -

nsdateformatter *dateformatter = [[nsdateformatter alloc] init]; dateformatter.dateformat = @"hh:mm:ss"; nstimezone *gmt = [nstimezone timezonewithabbreviation:@"gmt"]; [dateformatter settimezone:gmt]; nsdate *startdate = [dateformatter datefromstring:@"14:37:00"];     nslog(@"startdate---%@",startdate);  //this startdate---2000-01-01 14:37:00 +0000 (in simulator/ipod/iphone)  //  startdate---(null)  (in ipad) 

issue user's ipad's time format - if in 12 hour format - above code results null do issue ??

bacause time format set 12 hours on ipad device, date string in 24 hours format @ string @"14:37:00".

use

dateformatter.dateformat = @"hh:mm:ss"; [dateformatter setlocale:[[nslocale alloc] initwithlocaleidentifier:@"en_us"]; 

reference

if want force 12-hour mode, regardless of user's 24/12 hour mode setting, should set locale en_us_posix.

use hh instead of hh.

hh 12 hour time while hh 24 hour time.

a official reference this, as linked apple themselves, here. table here, mentioned zaph.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -