0
I need to show only the local time in a control TextBox
.
In the following format:
hh:mm:ss
How could I do that in C#?
0
I need to show only the local time in a control TextBox
.
In the following format:
hh:mm:ss
How could I do that in C#?
5
A possible way:
textBox1.Text = DateTime.Now.ToString("hh:mm:ss");
textBox1.Text = DateTime.Now.ToString("HH:mm:ss");
0
You can use a Binding so that the TextBox
is constantly updated as time goes on. The most direct way to do it is directly in XAML. It would look like this:
<TextBox Text="{Binding Source={x:Static sys:DateTime.Now}, StringFormat='HH:mm:ss ', Mode=OneWay}"/>
-1
An alternative to the @rubStackOverflow response:
DateTime n = DateTime.Now;
TextBox1.Text = String.Format("{0}:{1}:{2}", n.Hour, n.Minute, n.Second);
Browser other questions tagged c#
You are not signed in. Login or sign up in order to post.
You can use the
MaskedTextBox
for this purpose.– gato