iPhone Adjust Time in NSDate

Discussion in 'iOS Programming' started by newtoiphonesdk, Apr 26, 2012.

  1. newtoiphonesdk macrumors 6502a

    Jul 30, 2010
    I use an RSS Parser that is listing times wrong. Eastern Standard Time shows 1 hour later than what the actual time of the RSS Event is. So, I am trying to figure out how I can adjust this in code, so that in the cellForIndexAtPathRow method of TableView, it will show correct time. Here is the code I am using:
        NSDateFormatter * dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
        [dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
        [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
        NSString *articleDateString = [dateFormatter stringFromDate:entry.articleDate];
    The entry.articleDate comes from the RSS Parser earlier which returns:
        NSString *articleDateString = [item valueForChild:@"updated"];        
            NSDate *articleDate = [NSDate dateFromInternetDateTimeString:articleDateString formatHint:DateFormatHintRFC3339];
    What do you think would be the best way to take the HH part of the string only, and subtract 1 off of it?
  2. CodeBreaker macrumors 6502

    Nov 5, 2010
    Sea of Tranquility
    Can you post the actual date string you get from the RSS parser?
  3. MattInOz macrumors 68030


    Jan 19, 2006
    If you set the time zone of your time formatter do you get the times you are expecting?
  4. ArtOfWarfare macrumors G3


    Nov 26, 2007
    I would probably do something like:
    NSDate *modifiedDate = [NSDate dateWithTimeInterval:-3600 sinceDate:articleDate];
    The -3600 comes up with a date/time one hour earlier than the original one.

    To get the hour portion only, I'd create another date formatter that only outputs hour (I think you'll have to make your own, totally custom one,) and then use stringFromDate on it.

Share This Page