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

Current and future Microsoft (Expression) Blend Versions

Getting the Crisp back into your WPF Apps

Confluent Cloud Series - Part 1 : Getting the .Net examples to work