문제

I am using a UIDatePicker in the countdown timer mode. I want to take the current set time on the uidatepicker in seconds and put it in an integer value? How is this done?

도움이 되었습니까?

해결책

The UIDatePicker has a property called countDownDuration so you should be able to use

int seconds = (int)datePicker.countDownDuration;

Edit: to address concern in the comment, make sure to manually set either the countDownDuration or the time of the datePicker in order to get a "whole-minute" value. For instance, in viewDidLoad you could set:

datePicker.countDownDuration = 60.0f;

and then the default-selected time duration in your countdown would be exactly 0 hours, 1 minute. Otherwise, by default the date picker will use the current date/time and setting your countdown timer could result in countDownDuration being up to +59 seconds (e.g. 1 minute could ready anywhere from 60-119, 2 minutes from 120-179, etc) based on the time when you run your app.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top