UIDatePicker: temporary mode: initialize the time (should be simple)

All,

This seems like such a simple thing, but I cannot find the * correct method to create a UIDatePicker in temporary mode and initialize it until a certain time. I do not need a date - just the time (think about the alarm). I created an NSDate object:

NSDate * date = [[NSDate alloc] initWithTimeIntervalSinceReferenceDate: (NSTimeInterval) delta];
pickerView = [[UIDatePicker alloc] init];  // which should be 'now' right?
pickerView.datePickerMode = UIDatePickerModeTime;  // which creates just the clock
[pickerView setDate:date];

and in the first line, the interval (delta) is zero. It displays 7:00 PM.

It should be so simple that I will miss it, but I canโ€™t find the right path - anyone?

Thank you in advance!

: bp:

* Yes, I looked, but apparently not in the right places: (

+3
source share
3 answers

. 0AM, UTC.

0

, dkk - . , DatePicker, PickerView ( ). . .

0
NSDate *date = [NSDate date];
date = [[NSCalendar autoupdatingCurrentCalendar] dateFromComponents:[[NSCalendar autoupdatingCurrentCalendar] components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:date]];
date = [date dateByAddingTimeInterval:60 * 60 * 21];

pickerView.date = date;

Steps here with date

  • initialization date with current date
  • enter date at midnight
  • add a time interval to the date (60 seconds * 60 minutes * hour). In this case, 21 = 9 pm

It works for UIDatePickerwith datePickerModefrom UIDatePickerModeTimeandUIDatePickerModeCountDownTimer

0
source

Source: https://habr.com/ru/post/1762851/


All Articles