Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3347234
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:23:51+00:00 2026-05-18T01:23:51+00:00

I created a method to find the third Friday of every month. When I

  • 0

I created a method to find the third Friday of every month.

When I run it from Eastern time zone, all is well.

When I run it from Central, the dates are off.

My method:

-(NSDate*) getSaturdayAfterThirdFriday:(NSDate*)date {
    NSDate* resultDate = nil;

    if( date != nil ) {

        NSDateFormatter *df = [[NSDateFormatter alloc] init];

        // start at the 1st of the month
        NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

        NSTimeZone *zone = [NSTimeZone timeZoneWithName:@"EST"];
        [calendar setTimeZone:zone];
        NSDateComponents *comp = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:date];
        [comp setDay:1];
        date= [calendar dateFromComponents:comp];
        [calendar release];

        // count number of 'fri' (including today)
        BOOL foundFlag = NO;
        NSString* dateString = nil;
        NSInteger count = 0;

        [df setDateFormat:@"EEE"];

        while (foundFlag == NO) {
            dateString = [df stringFromDate:date];
            if( [dateString caseInsensitiveCompare:@"fri"] == 0 ) {
                count++;
                NSLog(@"Found Friday: %@", [date description]);
            }
            if( count >= 3 ) foundFlag = YES;
            else date = [NSDate dateWithTimeInterval:86400 sinceDate:date];
        }

        // get the next day (Saturday)
        resultDate = [NSDate dateWithTimeInterval:86400 sinceDate:date];

        [df release];
    }

    return resultDate;
}

The date that is passed is created with this method:

-(NSDate*) getDateForEasternTime:(NSDate*)date {
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSTimeZone *zone = [NSTimeZone timeZoneWithName:@"EST"];
    [calendar setTimeZone:zone];
    NSDateComponents *comp = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:date];
    date = [calendar dateFromComponents:comp];
    [calendar release];
    NSLog(@"getDateForEasternTime: %@", [date description]);
    return date;
}

I need to calculate dates based on Eastern Time only.

Here’s my log output for Eastern time zone:

getDateForEasternTime: 2010-11-14 05:00:00 GMT

Found Friday: 2010-11-05 05:00:00 GMT

Found Friday: 2010-11-12 05:00:00 GMT

Found Friday: 2010-11-19 05:00:00 GMT

And for Central Time:

getDateForEasternTime: 2010-11-14 05:00:00 GMT

Found Friday: 2010-11-05 05:00:00 GMT

Found Friday: 2010-11-13 05:00:00 GMT

Found Friday: 2010-11-20 05:00:00 GMT

What’s even more strange is that if I go further West in time zones, there is the discrepancy. If I go East in time zones there is none.

Any NSDate guru’s can help with this?

Edit:

When I refer to changing the time zone, I’m talking about changing the time zone on the device itself. The line:

NSTimeZone *zone = [NSTimeZone timeZoneWithName:@"EST"];

Remains unchanged.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:23:51+00:00Added an answer on May 18, 2026 at 1:23 am

    All your code is unnecessary. Using the weekday and weekdayOrdinal properties of NSDateComponents you can directly query a NSCalendar for the 3rd Friday of a month:

    NSDateComponents *components = [[NSDateComponents alloc] init];
    [components setWeekday:6];        // 1 = Sunday ... 7 = Saturday
    [components setWeekdayOrdinal:3]; // 3rd Friday  
    [components setMonth:11]; 
    [components setYear:2010];
    NSCalendar *currentCalendar = [NSCalendar currentCalendar];
    NSDate *date = [currentCalendar dateFromComponents:components];
    

    Also, there is almost the same example for this in the Developer Documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.