display the machine time in a textbox
-
hi, I want to display the time and date in a textbox using c# where i should put the formula and how regards
Use System.DateTime.Now textbox.Text=System.DateTime.Now.ToString(); at page load or any buttion's click event wherever you want.
Naresh Patel
-
Use System.DateTime.Now textbox.Text=System.DateTime.Now.ToString(); at page load or any buttion's click event wherever you want.
Naresh Patel
-
exactly. and use a timer if u want it to look like a clock:)
there are no facts, only interpretations
And use the conditional operator ?: to format it like a real clock:)
int Hours = ((YourTimeVariable / 1000) / 3600); int Minutes = ((YourTimeVariable / 1000) / 60) - (Hours \* 60); int Seconds = ((((YourTimeVariable / 1000)) - (Minutes \* 60)) - (Hours \* 3600)); strHours = Hours < 10 ? "0" + Hours.ToString() : Hours.ToString(); strMinutes = Minutes < 10 ? "0" + Minutes.ToString() : Minutes.ToString(); strSeconds = Seconds < 10 ? "0" + Seconds.ToString() : Seconds.ToString(); Time\_TextBox.Text = strHours + ":" + strMinutes + ":" + strSeconds;
Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)
-
And use the conditional operator ?: to format it like a real clock:)
int Hours = ((YourTimeVariable / 1000) / 3600); int Minutes = ((YourTimeVariable / 1000) / 60) - (Hours \* 60); int Seconds = ((((YourTimeVariable / 1000)) - (Minutes \* 60)) - (Hours \* 3600)); strHours = Hours < 10 ? "0" + Hours.ToString() : Hours.ToString(); strMinutes = Minutes < 10 ? "0" + Minutes.ToString() : Minutes.ToString(); strSeconds = Seconds < 10 ? "0" + Seconds.ToString() : Seconds.ToString(); Time\_TextBox.Text = strHours + ":" + strMinutes + ":" + strSeconds;
Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)
Muammar© wrote:
strHours = Hours < 10 ? "0" + Hours.ToString() : Hours.ToString();
strHours = Hours.ToString("D2");
etc. will suffice.Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
-
And use the conditional operator ?: to format it like a real clock:)
int Hours = ((YourTimeVariable / 1000) / 3600); int Minutes = ((YourTimeVariable / 1000) / 60) - (Hours \* 60); int Seconds = ((((YourTimeVariable / 1000)) - (Minutes \* 60)) - (Hours \* 3600)); strHours = Hours < 10 ? "0" + Hours.ToString() : Hours.ToString(); strMinutes = Minutes < 10 ? "0" + Minutes.ToString() : Minutes.ToString(); strSeconds = Seconds < 10 ? "0" + Seconds.ToString() : Seconds.ToString(); Time\_TextBox.Text = strHours + ":" + strMinutes + ":" + strSeconds;
Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)
Or maybe just use the ToString method :rolleyes: DateTime.Now.ToString("hh:mm:ss");
only two letters away from being an asset
-
Or maybe just use the ToString method :rolleyes: DateTime.Now.ToString("hh:mm:ss");
only two letters away from being an asset
-
Muammar© wrote:
strHours = Hours < 10 ? "0" + Hours.ToString() : Hours.ToString();
strHours = Hours.ToString("D2");
etc. will suffice.Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
-
Or maybe just use the ToString method :rolleyes: DateTime.Now.ToString("hh:mm:ss");
only two letters away from being an asset
-
And use the conditional operator ?: to format it like a real clock:)
int Hours = ((YourTimeVariable / 1000) / 3600); int Minutes = ((YourTimeVariable / 1000) / 60) - (Hours \* 60); int Seconds = ((((YourTimeVariable / 1000)) - (Minutes \* 60)) - (Hours \* 3600)); strHours = Hours < 10 ? "0" + Hours.ToString() : Hours.ToString(); strMinutes = Minutes < 10 ? "0" + Minutes.ToString() : Minutes.ToString(); strSeconds = Seconds < 10 ? "0" + Seconds.ToString() : Seconds.ToString(); Time\_TextBox.Text = strHours + ":" + strMinutes + ":" + strSeconds;
Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)