Jay1b Posted December 11, 2003 Posted December 11, 2003 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. Quote
Administrators PlausiblyDamp Posted December 11, 2003 Administrators Posted December 11, 2003 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Jay1b Posted December 11, 2003 Author Posted December 11, 2003 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.