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

  • SEARCH
  • Home
  • 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 4093272
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:35:51+00:00 2026-05-20T19:35:51+00:00

After trying to work on someone else’s code, and so many different iterations, I

  • 0

After trying to work on someone else’s code, and so many different iterations, I am unable to understand what am I doing wrong with dates on a calendar month view. I am trying to present a calendar in month view fashion like calendar.app but unfortunately some users in countries like Australia, UK are reporting incorrect alignment of Days to Dates. For instance in Australia it displays 17th March as Friday. Any help is highly appreciated!

Here is the code sample I am using:

-(void)setCalendar
{
    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *comps = [gregorian components:units fromDate:[NSDate date]];
    self.currentDate = [gregorian dateFromComponents:comps];
    NSInteger weekdayInteger=[comps weekday];
    currentMonth=[comps month]; 
    currentYear=[comps year];   
    NSString *dateString=[[NSString stringWithFormat:@"%@",currentDate] substringToIndex:10];
    NSArray *array= [dateString componentsSeparatedByString:@"-"];
    NSInteger currentDay=[[array objectAtIndex:2] intValue];
    currentMonthConstant=currentMonth;
    currentYearConstant=currentYear;
    currentDayConstant=currentDay;
    currentConstantDate=[NSString stringWithFormat:@"%d/%d/%d",currentDayConstant,currentMonthConstant,currentYearConstant];
    currentFirstDay=((8+weekdayInteger-(currentDay%7))%7);
    if(currentFirstDay==0)
        currentFirstDay=7;
    [gregorian release];
}

And this is how im populating the calendar:

-(void)fillCalender:(NSInteger)month weekStarts:(NSInteger)weekday year:(NSInteger)year
{

    currentMonth=month;
    currentYear=year;
    currentFirstDay=weekday;
    UIButton *temp;
    NSInteger numberOfDays=[self getNumberofDays:month YearVlue:year];
    currentLastDay=(currentFirstDay+numberOfDays-1)%7;
    if(currentLastDay==0)
        currentLastDay=7;
    NSString *monthName=[self getMonth:month];
    NSInteger grid=(weekday-1); 

    monthLabel.text=[NSString stringWithFormat:@"%@   %d",monthName,year];


    for(int i=1;i<=numberOfDays;i++)
    {
        if([frontView isEqualToString:@"view1"])
            temp=[arr_View2Buttons objectAtIndex:grid];
        else
            temp= [arr_View1Buttons objectAtIndex:grid];

        [temp setBackgroundImage:nil forState:UIControlStateNormal];

        [temp setUserInteractionEnabled:TRUE];
        UILabel *aLbl = (UILabel *)[temp viewWithTag:123];
        [aLbl setText:[NSString stringWithFormat:@"%d",i]];

        // check for today
        if(currentDayConstant == i && currentMonthConstant == currentMonth && currentYearConstant == currentYear)
        {
            [aLbl setTextColor:[UIColor blueColor]];
        }
        else
        {
            [aLbl setTextColor:[UIColor colorWithRed:69/255.0 green:2/255.0 blue:71/255.0 alpha:1.0]];
        }
        [temp setTag:i];

        grid++;
        if(grid==35)
            grid=0;
    }

}

And finally viewdidload:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setCalendar];
    // set views
    [self.view1 setFrame:CGRectMake(0,45,320,232)];
    [self.view2 setFrame:CGRectMake(0,277,320,232)];
    [self.view addSubview:self.view1];
    [self.view addSubview:self.view2];
    frontView = @"view2";
    [self fillCalender:currentMonth weekStarts:currentFirstDay year:currentYear];
    frontView = @"view1";
}
  • 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-20T19:35:51+00:00Added an answer on May 20, 2026 at 7:35 pm

    You need to change the code

    replace
    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

    with

    NSCalendar *currentCalendar = [NSCalendar currentCalendar];

    this will identify the current calendar from the device and will perform accordingly

    Hope this will solve your problem…

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

Sidebar

Related Questions

After trying to understand why client code is not rendered in a page (injected
I am doing short-term contract work for a company that is trying to implement
After trying to avoid JavaScript for years, Iv started using Query for validation in
After trying to setup my site for Google Webmaster Tools I found that my
I'm getting this error after trying to appendChild to an element that was just
I'm trying to call a function after I load some XML into Actionscript, and
I am trying to autoreload my page after every 20 seconds. I am using
I'm trying to make a data bound column invisible after data binding, because it
I'm trying to debug a deadlock in a multi-threaded Python application after it has
I'm trying to use class names to change the color of a link after

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.