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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:25:34+00:00 2026-06-01T16:25:34+00:00

Here’s my code: picker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0,40,0,0)]; picker.datePickerMode = UIDatePickerModeDateAndTime; picker.minuteInterval = 5;

  • 0

Here’s my code:

picker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0,40,0,0)];
picker.datePickerMode = UIDatePickerModeDateAndTime;
picker.minuteInterval = 5;
picker.minimumDate = [NSDate date];

Ok, It’s working fine until here. (Image: http://img29.imageshack.us/img29/8277/snap1r.png)

Days that are past in the DatePicker were all grayed out. It can’t be selected.
And minute Intervals are 5.

But now when I click any row that were already Grayed out. The date of DatePicker returns time of this moment.

For Example:I cliked “9” on the DatePicker (It’s already past time)
And the system time now is

22:27:57

and the Date of DatePicker returns: (Image: http://img42.imageshack.us/img42/2760/nslog.png)

2012-04-08 22:27

Because my minute interval is 5 minute, so I don’t hope the picker returns the value that can’t be divided by 5, this will cause my program crash.

Is this a Bug? or it’s just my problem?
thanks!

——To inspector g (Sorry my English isn’t very good)

Because the minuteInterval of Datepicker is 5. So the return value of DatePicker’s date only returns minute that can divded by 5 (etc. 0, 5 , 10 , 15 …..)

and also I have the property minimumDate set to [NSDate date], so that users can’t select the date in past.

but now of user click a row that was in past (grayed out), the DatePicker’s date return the time at that moment.

so the minute of date could be any value (0~60) but not I wished ( 0 , 5 , 10 , 15….)

I’ve tried my best to explain >”< please forgive.


To Inspector g.

Thanks for your code, I suddenly realized there’s a nice way to solve my problem.
But I dunno why, there are some problems if I use your code. (I guess it’s about timeZone)

But I follow your logic and re-write a code, I’ll share with you:

unsigned unitFlags_ = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit;
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *comps_ = [gregorian components:unitFlags_ fromDate:[jRemindPicker date]];
NSInteger remainder = [comps_ minute] % 5;

NSLog(@"%i-%i-%i %i:%i", comps_.year, comps_.month, comps_.day, comps_.hour, comps_.minute);

if ( remainder ) {
   /* My Own code /*
} else {
  /* My Own Code /*
}
[gregorian release];
  • 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-06-01T16:25:35+00:00Added an answer on June 1, 2026 at 4:25 pm

    Your description of the problem with selecting a date/time is a little unclear, so perhaps you can clarify? Provide a short screencast?

    In any event, it sounds like you cannot select a date before today, so your error is in this line:

    picker.minimumDate = [NSDate date];
    

    You are setting the minimum selectable date to the current date and time (as that’s what [NSDate date] returns.

    Remove that line and you should be able to select whatever date/time you wish.

    EDIT
    If the problem is that you can’t select a date in the future, try setting:

    picker.maximumDate = [NSDate distantFuture];
    

    Using your existing minimum and this new maximum, the range of selectable dates will be set to somewhere between today and a very long time after today.

    SECOND EDIT
    Thanks for clarifying! I see the problem now. When you receive the callback from the user changing the date, you have to round up or down appropriately. You can then use the rounded time at that point, or manually set the picker date/time to the rounded value via setDate: animated:

    For example:

    -(IBAction) pickerValueChanged:(id)selector_
    {
        UIDatePicker* picker = (UIDatePicker*) selector_;
    
        // get the minutes from the picker
        NSCalendar* calendar = [NSCalendar currentCalendar];
        NSDateComponents* components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:picker.date];
        NSInteger minutes = [components minute];
    
        // check if the minutes should be rounded
        NSInteger remainder = minutes % 5;
        if(remainder)
        {
            minutes += 5 - remainder;
            [components setMinute:minutes];
            picker.date = [calendar dateFromComponents:components];
        }
    
        // now picker.date is "safe" to use!
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code, which takes two version identifiers in the form 1, 5,
Here is an example: I write html code inside of textarea, then I swap
Here is my code...I have two dimensional matrices A,B. I want to develop the
Here is my code sample, let me know if it can be further improved?
Here is my code (Say we have a single button on the page that
here are 2 screen shots when i try to debug my code in visual
Here a simple question : What do you think of code which use try
Here is some code I made :) @echo off set source=R:\Contracts\ set destination=R:\Contracts\Sites\ ROBOCOPY
Here my code: $(document).ready(function() { $('#mid_select').live('click', function(e){ $('#middle').load( $(this).attr('href') + ' #middle'); var page
Here's my code. It tries to load Leaflet library. When I turn crossDomain option

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.