Sign in to follow this  
I Like Bread

[.net] Date/time

Recommended Posts

I'm trying to find a command that would enter the current date and time into a displayed string. As in:
"< div >The time is: " + ????? + "< /div >"
Anyone know how to do this?

Share this post


Link to post
Share on other sites
string.Format("
The time is : {0:hh:mm:ss}
",DateTime.Now);

You can of course use other formatting to write what you really want.

Share this post


Link to post
Share on other sites
Be careful with the Microsoft.VisualBasic namespace. It's mainly there to help you migrate vb6 code to .NET. Yes, it does work but MS strongly suggests you use the *real* framework classes/functions: in particular the Microsoft.VisualBasic.Compatibility namespace should be avoided. The namespace Microsoft.VisualBasic contains a lot of 'global' methods to give that vb6 feel..

Perhaps Lenolian's rating should go++ as well[smile]

Cheers

Share this post


Link to post
Share on other sites
If you want to do this in the "real" .Net way, you should be using the DateTime structure. It has a ton of useful string formatting functions, depending on what format you are looking for. What I usually use is "DateTime.Today.ToShortDateString()"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this