Search code examples
c#asp.netglobalization

Returning date in US format


I' like to return this short date in the US format, the current culture of my application is en-GB, but I'd like it in en-US.

Here's the code I have so far:

DateTime.Now.AddYears(-2).ToShortDateString();

Solution

  • Use .ToString() extension method and enter the format:

    DateTime.Now.AddYears(-2).ToString("M/d/yyyy");
    

    Custom date format options are documented here:

    http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx