Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

 

   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.

 

   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.

  • Administrators
Posted

some possible ways:

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...