Time?

  • Thread starter Thread starter Dean
  • Start date Start date
D

Dean

Hi,
I am using Vb.net and I want to know how to put the Time, Date
which ticks??

Please reply as soon as possible

Dean

PS: Please make the answer simple because I am only 11 Yrs old and New
to VB
 
Hi Dean,

Create a new project, or use an existing project - anything with a form.
Place a button and a label on the form, and name them btnUpdateTime and
lblTime respectively.
Add the following code to the form, and run the program.

Private Sub btnUpdateTime_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdateTime.Click
lblTime.Text = System.DateTime.Now.ToString("dd/mm/yyyy HH:mm:ss")
End Sub

To get the time to update every second, you'll need a Timer control. Drag
one from the toolbox on the left to the form.
Then double click on it (it moves to a tray below the form). Then modify
the code to this (same as above);

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
lblTime.Text = System.DateTime.Now.ToString("dd/mm/yyyy HH:mm:ss")
End Sub

The two routines are the difference between updating manually, and updating
using the timer. There are quite a few varied ways of doing this.

Hope that gets you going.
___________________________________________
The Grim Reaper
 
Hello, Dean,

There is only one thing I would modify in the Reaper's suggestions.
Please use format "yyyy/mm/dd HH:mm:ss" instead. It has too many
advantages to list here, but the most important is that you can't get
confused about whether it's a North American date or a European date.

That is, "12/02/2006" could be either December 2nd or February 12th,
just depending upon where you (or your readers) are. With 2006/02/12
there is no doubt about what is meant. Please become a convert.

Cheers,
Randy
 
It says there is a problem with
'System.EventArgs) Handles btnUpdateTime.Click'
Please help
 
Help,
It says there is a Error with
'System.EventArgs) Handles btnUpdateTime.Click '
and 'As' at the end of Private Sub btnUpdateTime_Click(ByVal sender As
System.Object, ByVal e
 
In the following code;

Private Sub btnUpdateTime_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdateTime.Click
lblTime.Text = System.DateTime.Now.ToString("dd/mm/yyyy HH:mm:ss")
End Sub

..... the first 2 lines are supposed to by typed on ONE line. This message
was wrapped when it was sent, so the text went onto 2 lines.
Alternatively, add an underscore, like so;

Private Sub btnUpdateTime_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles btnUpdateTime.Click
lblTime.Text = System.DateTime.Now.ToString("dd/mm/yyyy HH:mm:ss")
End Sub
___________________________________
The Grim Reaper
 
Randy,

I apologise whole-heartedly for being English. Excuse me.
How, exactly, is 2006/02/12 under "no doubt" over it's interpretation??
It could easily be 2006/Feb/12 or 2006/02/Dec - just depends on how you look
at it.
I usually write my dates using dddd, d MMMM yyyy - HH:mm:ss because I hate
the way the Windows is designed to dump out American formatted dates, even
with regional settings set to the UK.
It was only an example for an eleven year old to learn from - not a
statement of correct date/time formatting.
___________________________________________
The Grim Reaper
 
Hi, Grim,

No slight on anyone's nationality was intended here. Sorry if you took
it that way.

Though living in Europe at the moment, I'm originally a Canuck.
Whenever we must interpret a date we've been sadly stuck with the
problem of having to guess whether its European standard format or
American standard format.

Therefore, I find the international date formatting standard (ISO 8601)
"yyyy-mm-dd" very pleasing. And because it begins with a four digit
year (and the other "standard" formats do not) there is no question
which format it is. Hence, there is no doubt over interpretation. And
in my humble personal opinion, ANY use of a date format beginning with a
four digit year and not following with month and day in that order must
be strongly eschewed for the danger to communication that it represents.)

In addition to the uniformity of interpretation that it provides, there
are other advantages as well. For example, when dates are formatted
like this they will sort in what is (almost always) the preferred order.
for some other advantages, do a search on "standard date format".

Many countries (including Canada and many European) have already adopted
this international standard. Sadly, for me at least, I see that
Canadian banks have recently adopted the American format, this in spite
of the clear superiority and official national adoption of the
international standard.

Cheers,
Randy
 
Back
Top