Get timer time from UIDatePicker?
How do you get the time entered from a UIDatePicker?
I have a button to press, and I have an IBAction, so what code开发者_运维技巧 would get you the data?
I would also like the time entered on the timer, instead of starting a timer.
Oh yeah, and the Date Picker is a timer, not a date.
You have a UIDatePicker with datePickerMode set to UIDatePickerModeCountDownTimer?
To get the currently selected value, use:
NSTimeInterval duration = datePickerView.countDownDuration;
int hours = (int)(duration/3600.0f);
int minutes = ((int)duration - (hours * 3600))/60;
let t = datePicker.countDownDuration
let date = NSDate(timeIntervalSinceReferenceDate: t)
let calendar = NSCalendar(identifier: NSGregorianCalendar)!
calendar.timeZone = NSTimeZone(forSecondsFromGMT: 0)
var components = calendar.components(NSCalendarUnit.CalendarUnitHour | NSCalendarUnit.CalendarUnitMinute, fromDate: date)
var hour = components.hour
var minute = components.minute
return String(format: "%02d:%02d", hour, minute)
maybe this will help? UIDatePicker as timer(video on vimeo)
you can use the above code snippets, by using NSDate will result in todays date & the current time...
NSDate *dmd = [NSDate date];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSString *dateString = [dateFormatter stringFromDate:dmd];
NSArray *temp=[dateString componentsSeparatedByString:@""];
NSLog(@"%@",[temp objectAtIndex:1]);
精彩评论