Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting a DateTime to a shorthand month in English

I have a bit of code that's formatting the shorthand month name, see below, but I need the value to always return in English. This code currently seems to be translated into the appropriate language somehow?

Any ideas? Many thanks!

Response.write(myDateTimeValue.ToString("MMM"));  // Needs to always return Jan for all languages
like image 883
James Radford Avatar asked Jun 16 '11 14:06

James Radford


1 Answers

month.ToString("MMM", CultureInfo.InvariantCulture);

InvariantCulture is explicitly for situations where you always need the result to be the same, and always matches en-US. There is no need to create a new instance of CultureInfo.

like image 121
Sven Avatar answered Sep 21 '22 18:09

Sven