Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Take current Countdown Timer value

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?


1 Answers

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.

like image 123
Stonz2 Avatar answered Jun 23 '26 03:06

Stonz2



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!