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 7098095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:00:48+00:00 2026-05-28T11:00:48+00:00

I have created a custom class for my dates and need move dates forward

  • 0

I have created a custom class for my dates and need move dates forward and backward via button . Here is my code which shows Today date :

- (NSString *) showToday {

    NSCalendar *myCal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

    [dateFormatter setCalendar:myCal];

    offsetComponents = [[NSDateComponents alloc] init];
//shows today 
    [offsetComponents setDay:0];

    NSDate *nextDate = [myCal dateByAddingComponents:offsetComponents toDate:[NSDate date] options:0];

    [dateFormatter setDateFormat:@"d"];
    NSString *currDay = [dateFormatter stringFromDate:nextDate];

    [NSString stringWithFormat:@"%@",currDay];

    [myCal release];
    [dateFormatter release];
    return currDay;
}

on my viewController :

customClass = [[customClass alloc]init];

    day.text = [cal showToday];

so if I need to move forward a date I just change this line code to :

//show tomorrow 
[offsetComponents setDay:1];

so How can I dynamically change this line and change dates via button ?

  • 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-28T11:00:48+00:00Added an answer on May 28, 2026 at 11:00 am

    You can declare an int for your offsetComponents variable. then :

    - (IBAction)moveDatesForward:(id)sender {
    
        NSCalendar *persCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSPersianCalendar];    
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        NSLocale *IRLocal = [[NSLocale alloc] initWithLocaleIdentifier:@"fa_IR"];
        [dateFormatter setLocale:IRLocal];
        [dateFormatter setCalendar:persCalendar];
    
        offsetComponents = [[NSDateComponents alloc] init];
    
        offsetComponents.day = _dayNumber;
    
        NSDate *nextDate = [persCalendar dateByAddingComponents:offsetComponents toDate:[NSDate date] options:0];
    
        [dateFormatter setDateFormat:@"d"];
        dayLabel.text = [dateFormatter stringFromDate:nextDate];
    
        [NSString stringWithFormat:@"%@",dayLabel];
    
        [persCalendar release];
        [dateFormatter release];
    
          _dayNumber ++;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a custom class which show time date formatter and I need
i have created a custom view class which is a subclass of UIview class
I have created my custom MembershipProvider. I have used an instance of the class
friends, i have created custom title bar using following titlebar.xml file with code <?xml
If have created a custom role within SqlServer which I added to the db__denydatareader
I have created a custom list as a feature in sharepoint. i need to
I have created a custom form class and template for my form by following
I have created a Custom Validation Attribute: public sealed class DateAttribute : DataTypeAttribute {
I have created custom result class to serialize json data to xml. I want
I have 2 Lists containing entries of a custom class I have created. Basically,

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.