Get the complete month name in English

前端 未结 6 578
予麋鹿
予麋鹿 2021-01-17 07:31

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

6条回答
  •  萌比男神i
    2021-01-17 08:00

    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.

提交回复
热议问题