Reputation:
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?
Upvotes: 3
Views: 6068
Reputation: 6396
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.
Upvotes: 6