-1

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.

Thomas Athanasiou
  • 121
  • 1
  • 2
  • 11

2 Answers2

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
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