Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Set date of a Date Picker in Objective C

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 3.20k
    Comment on it

    In objective C, UIDatePicker is the best way to display date and time options. We can set date of our choice in a Date picker. Also we can set minimum and maximum date.

    Here I am creating UIDatePicker first.

            UIDatePicker *pickerDate=[[UIDatePicker alloc]initWithFrame:pickerFrame];
            pickerDate.datePickerMode=UIDatePickerModeDateAndTime;
    

    We can set limits also. Here is the code:-

    //Here I am setting 1 Hour interval to the current date.
            NSDate *date = [NSDate dateWithTimeInterval:3600.0 sinceDate:[NSDate date]];
            [pickerDate setMaximumDate:date];
            [pickerDate setMinimumDate:pickerDate.date];
    

    Here is the code to add time in seconds to set the interval.

    //Here I am setting 2 mins interval to the current date.
          pickerDate.date = [NSDate dateWithTimeInterval:120.0 sinceDate:[NSDate date]];
    

    Happy Coding!!!

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: