Forum Xamarin.Forms

How to format time in time picker ?

ksoluckyksolucky USMember ✭✭

I am using time picker as

        timePicker = new TimePicker()
        {
            Time = DateTime.Now.TimeOfDay,
            Format = ??? ,
            TextColor = Color.FromHex("#ffffff"),
            HorizontalOptions = LayoutOptions.FillAndExpand
        };

Right now without Format, I am getting time as HH:MM:SS.SSSSSSSS. I just want HH:MM. How to mention format for that ?

Tagged:

Posts

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    I think you should have a custom renderer
  • DaveHuntDaveHunt USMember ✭✭✭✭✭
    Format = "HH:mm"
    

    or

    Format = "hh:mm"
    

    depending on whether you want 24-hour or 12-hour format.

    See Custom Date and Time Format Strings for details.

  • ksoluckyksolucky USMember ✭✭

    Hello David,
    I have kept the Format = "hh:mm" but still am getting time as HH:MM:SS.SSSSS

  • DaveHuntDaveHunt USMember ✭✭✭✭✭

    You're going to have to show more of your code. How are you getting and displaying the time value? If you're just referencing the Time property and using ToString(), you're going to get the default TimeSpan time format, not the format you specified in the Format property. The Format property is just what the TimePicker uses to display the time in the picker.

Sign In or Register to comment.