Posts: 18
Threads: 4
Joined: Aug 2012
Reputation:
0
hi everyone..
i have a little problem with time
i know the code to get the system time but the problem
is as soon i started the program it only gets the time when the program started. what i want is the time or should i say also the seconds,minutes is counting too.
Posts: 159
Threads: 25
Joined: Mar 2012
Reputation:
0
Hello, jochen29.
What you want to do, in order to get full computer's time (without date), is declare four variables and set its values like this:
[code2=vbnet]hours = My.Computer.Clock.LocalTime.Hour ' Integer
minutes = My.Computer.Clock.LocalTime.Minute ' Integer
seconds = My.Computer.Clock.LocalTime.Second ' Integer
time = hours & ":" & minutes & ":" & seconds ' String[/code2]
If you want your hours, minutes and seconds to update as real time, add a new timer, set its interval to 1000 (1 second), enable it and set the values in timer's sub. It would look like this:
[code2=vbnet]Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
hours = My.Computer.Clock.LocalTime.Hour
minutes = My.Computer.Clock.LocalTime.Minute
seconds = My.Computer.Clock.LocalTime.Second
time = hours & ":" & minutes & ":" & seconds
End Sub[/code2]
Hopefully this solves your problem.
Also known as Rocketalypse.
System.out.println("I prefer Java.");