set current time in textbox

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2008
Posts: 18
Reputation: thijscream is an unknown quantity at this point 
Solved Threads: 0
thijscream thijscream is offline Offline
Newbie Poster

set current time in textbox

 
0
  #1
Jul 9th, 2008
can someone explain to me how to put the current time into a tekstbox...
i'm totaly new with this language and need to finish a program before school starts again.

it should be like this:

if i push button "BtnStart" then current time should be inputted in "textbox1"
if i push button "BtnStop" then current time should be inputten in "textbox2"
and time difference shouold be shown in "textbox3"

can someone help me with this?
i used to program this in delphi what i managed to work but never done anything with C# 2005
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 509
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 88
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro

Re: set current time in textbox

 
0
  #2
Jul 9th, 2008
Hi,
To get the Current Time u can use DateTime.Now property. It returns CurrentTime. So in btnStart u can use like this

  1. private void btnStart_Click(object sender, EventArgs e)
  2. {
  3. //Display the current Time
  4. textBox1.Text = DateTime.Now.ToString("hh:mm:ss tt");
  5. textBox2.Text = DateTime.Now.ToString("hh:mm:ss tt");
  6. //Start the Timer
  7. tmrTime.Enabled = true;
  8. }

Be sure to have three TextBoxes (textBox1, textBox2, textBox3)

  1. DateTime.Now.ToString (String s)
Provides you to format the Time
like hour : min : secs

Draw a Timer controls and Make Enable property to false, Interval Property to 1000 and Add TimerTick handler

  1. private void tmrTime_Tick(object sender, EventArgs e)
  2. {
  3. //Periodically update the values
  4. textBox2.Text = DateTime.Now.ToString("hh:mm:ss tt");
  5. }

This again change the time to DateTime variables.

At last Display the different in TextBox3
and Stop the timer
  1. private void btnStop_Click(object sender, EventArgs e)
  2. {
  3. DateTime dateTime1, dateTime2;
  4. // Change Time String to DateTime object
  5. dateTime1 = DateTime.Parse(textBox1.Text);
  6. dateTime2 = DateTime.Parse(textBox2.Text);
  7. //Find the Difference
  8. TimeSpan timeDiff = dateTime2.Subtract(dateTime1);
  9. //Display the Difference
  10. textBox3.Text = timeDiff.ToString();
  11. //Stop the Timer
  12. tmrTime.Enabled = false;
  13. }
KSG
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 23
Reputation: $dunk$ is an unknown quantity at this point 
Solved Threads: 5
$dunk$ $dunk$ is offline Offline
Newbie Poster

Re: set current time in textbox

 
0
  #3
Jul 9th, 2008
Why did you do the guys homework for him? A simple textBox2.Text = dateTime.ToString("hh:mm:ss tt"); would have sufficed.

All you do by doing someone's homework for them is encourage more of those kinds of questions without them putting any effort at all to at least take a stab at it.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 18
Reputation: thijscream is an unknown quantity at this point 
Solved Threads: 0
thijscream thijscream is offline Offline
Newbie Poster

Re: set current time in textbox

 
0
  #4
Jul 10th, 2008
tanx for info. this is just a litle piece of the homework i have to do
is alot more.. and will have to find out alot myself but i start learning this language now and it's getting more and more easy... although delphi is alot more easy ^^
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 1
Reputation: emmy_23 is an unknown quantity at this point 
Solved Threads: 0
emmy_23 emmy_23 is offline Offline
Newbie Poster

Re: set current time in textbox

 
0
  #5
Mar 24th, 2009
i have textbox,listbox and a button.i want when i enter a date in textbox.the specified data in listbox is displayed which is from a log file.Now.I want only when i select a current time,only the output data is displayed,not all teh data which displayed before
here is the code for the button to display the data.
  1. if (BioBridgeSDK.ReadGeneralLog(ref log) == 0)
  2. {
  3. while (BioBridgeSDK.GetGeneralLog(ref EnrollNo, ref yr, ref mth, ref day_Renamed, ref hr, ref min, ref sec, ref ver, ref io, ref work) == 0)
  4. <span class="ad_notxt"><code class="inlinecode"> //read the information logs from the memory buffer</code></span> {
  5. if (io == 0)
  6. {
  7.  
  8. listBox2.Items.Add(("No: " + Convert.ToString(EnrollNo) + " Date:" + Convert.ToString(day_Renamed) + "/" + Convert.ToString(mth) + "/" + Convert.ToString(yr) + " Time: " + Convert.ToString(hr) + ":" + Convert.ToString(min) + ":" + Convert.ToString(sec) + " I/O: Check In"));
  9. //listBox2.Items.Add(textBox2.TextChanged);
  10. }
  11. else
  12. listBox2.Items.Add(("No: " + Convert.ToString(EnrollNo) + " Date:" + Convert.ToString(day_Renamed) + "/" + Convert.ToString(mth) + "/" + Convert.ToString(yr) + " Time: " + Convert.ToString(hr) + ":" + Convert.ToString(min) + ":" + Convert.ToString(sec) + " I/O: Check Out"));
  13. // if (textBox2.Text = DateTime())
  14. {
  15.  
  16.  
  17. }
i dont know what to write in order to make the selected date to appear the specified log.Also,do i need textBox2_TextChanged
to be fired each time i change teh date in the textbox or not?.

Thanks,
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC