3

My app uses a feed from localendar.com to create a tableview of upcoming events. The issue though, is that the feeds from localendar do not account for DST, so they end up showing the pubDate of the feed as 1 hour later than the event actually starts. My app parses the feed and takes the date into the detail line in the cell, which makes it confusing. I am trying to get my app to detect whether or not the user is in DST, and if they are, subtract one hour from the date. However, when I use the code below, nothing changes, and a NSLog never gets called on the isDaylightSavingsTime property tag.

UPDATE:

I have tried a different approach in changing it up in the cellForRowAtIndexPath:

NSDateFormatter * dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
    [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
    [dateFormatter setDateStyle:NSDateFormatterShortStyle];


    NSString *articleDateString = [dateFormatter stringFromDate:entry.articleDate];
    NSLog(@"after formatter %@", articleDateString);



       cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", articleDateString];

The issue is that the time in the RSS feed pubDate does not adjust for DST, so it is an hour off half of the year. The formatter does everything correct by time zone, because the time in the feed is already wrong as it uses GMT and not US Time.

PLEASE, do NOT vote to close this. This is not too localized, it applies to every state in the USA that has daylight savings time.

Here are two pics to describe the issue better. The first shows what is in the RSS Feed, and the second shows what is in the calendar which is the correct time.

enter image description here

As you see, that time in the feed shows as 10:00, while the actual time that displays every place BUT the RSS feed shows as:

enter image description here

Update 2:

I tried setting the timezone to Central manually in my code, but it still does the same thing. In cellForRowAtIndexPath I have:

RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];

    NSDateFormatter * dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"America/Menominee"]]; 
    [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
    [dateFormatter setDateStyle:NSDateFormatterShortStyle];
       cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", articleDateString];

However, instead of getting the detailTextLabel.text to show 5/27/13 10:00 PM, it shows 5/27/13 11:00 PM still.

4

2 回答 2

1

advise the use of

[formatter setTimeZone:localTimeZone];

instead.

于 2013-05-24T19:06:20.387 回答
0

似乎问题在于他们使用“CST”显示所有日期,但他们正在进行 DST 更正。CST 永远不会返回 YES,isDaylightSavingTime因为它是这样定义的;夏令时生效时,“中部时间”从 CST 更改为 CDT。

解决此问题的最简单方法是忽略提要中的时区标识符,并始终将日期视为相对于[NSTimeZone timeZoneWithName:@"America/Menominee"]. (或中部时间的其他时区。)

编辑:要清楚,您需要在解析日期时设置 NSDateFormatter 的时区,而不是在格式化显示时设置。也就是说,您需要进行的更改不在您显示的代码中。

于 2013-05-25T13:18:00.643 回答