i'm using class of nsdate+internettime parsing xmls calendars, blogs, etc. in central time zone , when view tableview showing each rss item, time listed correct. however, if user in est shows hour later, , earlier times mountain , pacific time zones. ideas why may be? code parsing date is:
the code in class nsdate+internettime is:code:nsstring *articledatestring = [item valueforchild:@"updated"]; nsdate *articledate = [nsdate datefrominternetdatetimestring:articledatestring formathint:dateformathintrfc3339];
&code:+ (nsdate *)datefrominternetdatetimestring:(nsstring *)datestring formathint:(dateformathint)hint { nsdate *date = nil; if (hint != dateformathintrfc3339) { // try rfc822 first date = [nsdate datefromrfc822string:datestring]; if (!date) date = [nsdate datefromrfc3339string:datestring]; } else { // try rfc3339 first date = [nsdate datefromrfc3339string:datestring]; if (!date) date = [nsdate datefromrfc822string:datestring]; } return date; }
i love have shows same time time zones. put in app times calendar events in est or whatever. thoughts?code:+ (nsdate *)datefromrfc3339string:(nsstring *)datestring { // create date formatter static nsdateformatter *dateformatter = nil; if (!dateformatter) { nslocale *en_us_posix = [[nslocale alloc] initwithlocaleidentifier:@"en_us_posix"]; dateformatter = [[nsdateformatter alloc] init]; [dateformatter setlocale:en_us_posix]; [dateformatter settimezone:[nstimezone timezoneforsecondsfromgmt:0]]; [en_us_posix release]; } // process date nsdate *date = nil; nsstring *rfc3339string = [[nsstring stringwithstring:datestring] uppercasestring]; rfc3339string = [rfc3339string stringbyreplacingoccurrencesofstring:@"z" withstring:@"-0000"]; // remove colon in timezone ios 4+ nsdateformatter breaks. see https://devforums.apple.com/thread/45837 if (rfc3339string.length > 20) { rfc3339string = [rfc3339string stringbyreplacingoccurrencesofstring:@":" withstring:@"" options:0 range:nsmakerange(20, rfc3339string.length-20)]; } if (!date) { // 1996-12-19t16:39:57-0800 [dateformatter setdateformat:@"yyyy'-'mm'-'dd't'hh':'mm':'sszzz"]; date = [dateformatter datefromstring:rfc3339string]; } if (!date) { // 1937-01-01t12:00:27.87+0020 [dateformatter setdateformat:@"yyyy'-'mm'-'dd't'hh':'mm':'ss.ssszzz"]; date = [dateformatter datefromstring:rfc3339string]; } if (!date) { // 1937-01-01t12:00:27 [dateformatter setdateformat:@"yyyy'-'mm'-'dd't'hh':'mm':'ss"]; date = [dateformatter datefromstring:rfc3339string]; } if (!date) nslog(@"could not parse rfc3339 date: \"%@\" possibly invalid format.", datestring); return date; }
update:
in cellforrowatindexpath of tableview had:
i added in blank line is:code:nsdateformatter * dateformatter = [[[nsdateformatter alloc] init] autorelease]; [dateformatter settimestyle:nsdateformattermediumstyle]; [dateformatter setdatestyle:nsdateformattermediumstyle]; nsstring *articledatestring = [dateformatter stringfromdate:entry.articledate]; cell.textlabel.text = entry.articletitle; cell.detailtextlabel.text = [nsstring stringwithformat:@"%@ - %@", articledatestring, entry.blogtitle];
i tried messing sorts of different time zones, , never changed, yet if changed time zone of phone, times change.code:[dateformatter settimezone:[nstimezone timezonewithabbreviation:@"est"]];
or let me ask way. possible use dateformatter take time being returned, , either add or subtract hours it?
Forums iPhone, iPad, and iPod Touch iOS Programming
- iPhone
- Mac OS & System Software
- iPad
- Apple Watch
- Notebooks
- iTunes
- Apple ID
- iCloud
- Desktop Computers
- Apple Music
- Professional Applications
- iPod
- iWork
- Apple TV
- iLife
- Wireless
No comments:
Post a Comment