Get the Date-String (and only that) from a DateTime

Up to now, whenever I tried to get today's date in C#, I used DateTime.Today and
started chopping away the time information using substrings.

However, the DateTime type offers a method ToShortDateString() that does exactly what
I did in three lines before PLUS it is hooked up with the thread's current culture.


// old version, works for de-DE only
DateTime.Now.ToString(new CultureInfo("de-DE")).Substring( 0, 10 );

// new version, culture safe
DateTime.Now.ToShortDateString();


More useful DateTime stuff can be found here.

Kommentare

Beliebte Posts aus diesem Blog

Using AutoMapper for MVVM implementations

Deploying ClickOnce-applications in different environments without modifying the assembly identity

Preparing for and passing MCTS exam 70-536