How to get the time of a TimeSelector by omitting the date

0

Assign to a TextBox ONLY the time of a TimeSelector, I am trying to do it in these 3 ways but I can not do it.

Dim Hora As DateTime = DateTime.ParseExact(txtTotalHoras.Text, "HH:mm", CultureInfo.InvariantCulture)'opcion1
Dim Hora As DateTime = DateTime.ParseExact(txtTotalHoras.Text, "HH:mm", System.Globalization.CultureInfo.InvariantCulture)'opcion2
Dim Hora As DateTime = DateTime.Parse(String.Format("{0}:{1}", TimeSelector1.Hour, TimeSelector1.Minute))' opcion 3
txtTotalHoras.Text = Hora 
    
asked by yulfredy rodriguez 03.06.2017 в 01:39
source

1 answer

0

The way to do it is by creating an object of type DateTime and formatting it in the following way:

 Dim time As DateTime = DateTime.Parse(String.Format("{0}:{1}:{2} {3}", TimeSelector1.Hour, TimeSelector1.Minute, TimeSelector1.Second, TimeSelector1.AmPm))

Then the created object time is simply assigned to the textBox with the property ToLongTimeString

TextBox1.Text = time.ToLongTimeString 

Finally, the code remains:

 Protected Sub Button1_Click(sender As Object, e As EventArgs)
        Dim time As DateTime = DateTime.Parse(String.Format("{0}:{1}:{2} {3}", TimeSelector1.Hour, TimeSelector1.Minute, TimeSelector1.Second, TimeSelector1.AmPm))
        TextBox1.Text = time.ToLongTimeString
    End Sub
    
answered by 06.06.2017 в 20:18