I am trying to get hour and minutes from a timepicker on Xamarin pcl project. I want to convert them to integers. Is there a getHour or getMinutes method that i can use? I cannot find it. I need this to work on the Portable project NOT on android.
Asked
Active
Viewed 101 times
2 Answers
1
TimePicker returns a Timespan, which has Hours and Minutes properties
var time = myTimeSpan.Time;
int hour = time.Hours;
int min = time.Minutes;

Jason
- 86,222
- 15
- 131
- 146
-
Thank you sir. Do you know how to set the timePicker on the current time? (Device's time) – Thomas Athanasiou Oct 24 '17 at 18:45
-
yes, set the Time property. There is an example in the linked docs page – Jason Oct 24 '17 at 18:51
0
As Jason says, TimePicker returns a Timespan, which has Hours and Minutes properties
var time = myTimeSpan.Time;
int hour = time.Hours;
int min = time.Minutes;
In the same way you can set the Timespan
based on current time as follows:
timePicker.Time = DateTime.Now.TimeOfDay;

Jesus Angulo
- 2,646
- 22
- 28