UiDatePicker giving wrong time?

Heino126Heino126 NLMember

I am making an fun easy app to register working hours, just for myself.
I would like to get my start time and end time by using an DatePicker and only set to Time.
First the hours were off, googled it and found out that it is using the Zulu timezone, fixed that by doing this: https://gyazo.com/bc8a469c7f899a7b18a15c5707e5f792
But now I run in to the problem that the minutes are inaccurate if untouched. It is as of it using the current time and only if the hours are adjusted, it edits the hours, if the minutes are adjusted is edits the minutes.

Best Answer

Answers

  • NarenSharmaNarenSharma INMember ✭✭

    use this code

    void TimeChanged (object sender, EventArgs e)
    {
    var dateTime =DateTime.SpecifyKind ((System.DateTime)TimePicker.Date, DateTimeKind.Utc).ToLocalTime ();
    var selectedDate = dateTime.ToString ("dd-MM-yyyy");
    var selectedTime = dateTime.ToString ("HH:mm");

            lblTime.Text = selectedTime;
    

    }

  • Heino126Heino126 NLMember

    @NarenSharma

    I think I wasn't clear, my bad. I can get the time, that is not a problem, but thank for your response!

    My problem is, if I dont touch the selector wheel, it returns the current dateTime. For example, if it is currently 15:37, and the wheel is on 15:30 and untouched, I get 15:37 returned. If I change the wheel to 16:30, I get 16:37 returned. Only when I change the hours and the minutes on the wheel, I get the correct time.

Sign In or Register to comment.