Date & Time

Jay1b

Contributor
Joined
Aug 3, 2003
Messages
640
Location
Kent, Uk.
Hi

I was wondering what the best way to display the date and time is? Below is what i believe to be the correct '.NET' way - but to me it just seems stupidly long and awkward.

Visual Basic:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim moment As New DateTime
        moment = DateTime.Now
        MsgBox(moment.Hour & ":" & moment.Minute & ":" & moment.Second & "  " & moment.Day & "/" & moment.Month & "/" & moment.Year)

    End Sub

The other way, is more of a bring a cross from VB6 and is below, but to me this seems far superior.

Visual Basic:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        MsgBox(Format(Now, "hh:mm:ss  dd/MM/yyyy"))
        End Sub

What is the benefit of one method over another? Also is there a better way of doing this?

Thanks.
 
some possible ways:
Visual Basic:
Dim moment As Date = Date.Now
MessageBox.Show(moment.ToLongTimeString() & " " & moment.ToLongDateString())
'or
MessageBox.Show(moment.ToString("F"))
'or 
MessageBox.Show(moment.ToString("hh:mm:ss  dd/MM/yyyy"))

by the way MessageBox.Show is more .Net the the VB6 msgbox function.
 
by the way MessageBox.Show is more .Net the the VB6 msgbox function.

lol - True but thats one thing i am not changing until i am forced too! :D

Thanks for those. The third one was the one i was after.
 
Back
Top