VB.NET realtime clock in a textbox

user2782104 picture user2782104 · Nov 18, 2013 · Viewed 37.5k times · Source

How can I make it so that when I load the form a textbox will show me (dd/mm/yyy hh:mm:ss) format clock that is actually moving and is synced with the system?

I tried googling it but so far couldn't find anything that works. Most answers dealt with making labels into clocks but I figured it's the same with textboxes and tried doing what they said with no results. It shows me the time but it's just the time when the form loaded not an actual moving clock. I think most of the answers I found on google are dealing with older versions of VB that's why I can't get it to work.

P.S. I'm just learning coding so the simpler the code the better. Many step by step (like I'm 5) comments are appreciated as well. Thank You

Answer

Malcolm Salvador picture Malcolm Salvador · Nov 18, 2013

Add a Timer to your form, and add this code to it's tick event.

 Textbox1.text = Format(Now, "yyyy-MM-dd hh:mm:ss")

You now have a textbox which tells you the current date and time. Don't forget to enable your timer, though!