I use DateTime.Now.ToString(\"MMMM\")
in order to get the current month\'s full name. It works well, but I get it in Hebrew.
Is there an option to
Pass in the culture in which you want the name formatted. Like this:
DateTime.Now.ToString("MMMM", new CultureInfo("en-GB"));
An alternative option to the ones given by other posters:
int month = DateTime.Now.Month;
// Or use CultureInfo.InvariantCulture if you want
CultureInfo usEnglish = new CultureInfo("en-US");
DateTimeFormatInfo englishInfo = usEnglish.DateTimeFormat;
string monthName = englishInfo.MonthNames[month - 1];
I'm not saying it's better or worse than anything else - just an alternative.
You can either set the culture of the thread:
DateTime dt = DateTime.Now;
// Sets the CurrentCulture property to U.S. English.
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
// Displays dt, formatted using the ShortDatePattern
// and the CurrentThread.CurrentCulture.
Console.WriteLine(dt.ToString("MMMM"));
Or you can pass a CultureInfo
to the DateTime.ToString()
function.
// Creates a CultureInfo for U.S. English.
CultureInfo ci = new CultureInfo("en-US");
// Displays dt, formatted using the ShortDatePattern
// and the CultureInfo.
Console.WriteLine(dt.ToString("MMMM", ci));
Note that you could also choose CultureInfo.InvariantCulture.
Use the overload that takes a IFormatProvider
:
CultureInfo culture = new CultureInfo("en-GB");
DateTime.Now.ToString("MMMM", culture));
Source
You can pass a CultureInfo
object as an argument DateTime.ToString()
:
CultureInfo ci = new CultureInfo("en-US");
var month = DateTime.Now.ToString("MMMM", ci);
// alternatively you can use CultureInfo.InvariantCulture:
var month = DateTime.Now.ToString("MMMM", CultureInfo.InvariantCulture);
you can use CultureInfo.CreateSpecificCulture(CultureName)
to get month name in different languages.
Refer this
Creates a CultureInfo that represents the specific culture that is associated with the specified name.
string MonthName = DateTime.Now.ToString("MMMM", CultureInfo.CreateSpecificCulture(CultureName));
For a list of predefined culture names, see the National Language Support (NLS) API Reference at the Go Global Developer Center
// CULTURE SPECIFIC CULTURE
// Invariant Language (Invariant Country)
// af Afrikaans af-ZA
// am Amharic am-ET
// ar Arabic ar-SA
// arn Mapudungun arn-CL
// as Assamese as-IN
// az Azerbaijani az-Latn-AZ
// az-Cyrl Azerbaijani (Cyrillic) az-Cyrl-AZ
// az-Latn Azerbaijani (Latin) az-Latn-AZ
// ba Bashkir ba-RU
// be Belarusian be-BY
// bg Bulgarian bg-BG
// bn Bengali bn-IN
// bo Tibetan bo-CN
// br Breton br-FR
// bs Bosnian bs-Latn-BA
// bs-Cyrl Bosnian (Cyrillic) bs-Cyrl-BA
// bs-Latn Bosnian (Latin) bs-Latn-BA
// ca Catalan ca-ES
// co Corsican co-FR
// cs Czech cs-CZ
// cy Welsh cy-GB
// da Danish da-DK
// de German de-DE
// dsb Lower Sorbian dsb-DE
// dv Divehi dv-MV
// ...
// ta Tamil ta-IN
// te Telugu te-IN
// tg Tajik tg-Cyrl-TJ
// tg-Cyrl Tajik (Cyrillic) tg-Cyrl-TJ
// th Thai th-TH
// tk Turkmen tk-TM
// tn Setswana tn-ZA
// tr Turkish tr-TR
// tt Tatar tt-RU
// tzm Tamazight tzm-Latn-DZ
// tzm-Latn Tamazight (Latin) tzm-Latn-DZ
// ug Uyghur ug-CN
// uk Ukrainian uk-UA
// ur Urdu ur-PK
// uz Uzbek uz-Latn-UZ
// uz-Cyrl Uzbek (Cyrillic) uz-Cyrl-UZ
// uz-Latn Uzbek (Latin) uz-Latn-UZ
// vi Vietnamese vi-VN
// wo Wolof wo-SN
// xh isiXhosa xh-ZA
// yo Yoruba yo-NG
// zh Chinese zh-CN
// zh-CHS Chinese (Simplified) Legacy zh-CN
// zh-CHT Chinese (Traditional) Legacy zh-HK
// zh-Hans Chinese (Simplified) zh-CN
// zh-Hant Chinese (Traditional) zh-HK
// zu isiZulu zu-ZA