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

WPF Diaries : Using HLSL pixel shaders

Getting the Crisp back into your WPF Apps

WPF and Workflow Foundation : XAML parser compatibility issues