I need to show only the local time in a TextBox
control.
In the following format:
hh:mm:ss
How could I do this in C #?
I need to show only the local time in a TextBox
control.
In the following format:
hh:mm:ss
How could I do this in C #?
One possible way:
textBox1.Text = DateTime.Now.ToString("hh:mm:ss");
textBox1.Text = DateTime.Now.ToString("HH:mm:ss");
You can use a binding so that TextBox
is constantly updated as time passes. The most direct way to do this is directly in XAML. It would look like this:
<TextBox Text="{Binding Source={x:Static sys:DateTime.Now}, StringFormat='HH:mm:ss ', Mode=OneWay}"/>
An alternative to the @rubStackOverflow response:
DateTime n = DateTime.Now;
TextBox1.Text = String.Format("{0}:{1}:{2}", n.Hour, n.Minute, n.Second);