Get Month name from month number
Możliwy duplikat:
Jak uzyskać MonthName w c#?
Użyłem następującej składni c#, aby uzyskać nazwę miesiąca z miesiąca no, ale dostaję August
Chcę tylko Aug
..
System.Globalization.DateTimeFormatInfo mfi = new
System.Globalization.DateTimeFormatInfo();
string strMonthName = mfi.GetMonthName(8).ToString();
Wszelkie sugestie... 9 answers
Dla nazw krótkich miesięcy użyj:
string monthName = new DateTime(2010, 8, 1)
.ToString("MMM", CultureInfo.InvariantCulture);
Dla długich / pełnych nazw miesięcy dla kultury hiszpańskiej ("es")
string fullMonthName = new DateTime(2015, i, 1).ToString("MMMM", CultureInfo.CreateSpecificCulture("es"));
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-12-30 13:53:12
Dla Skróconych Nazw Miesięcy:"Aug"
DateTimeFormatInfo.Metoda GetAbbreviatedMonthName (Int32)
Zwraca skróconą nazwę danego miesiąca dla danej kultury na podstawie kultury związanej z aktualną Datąformatinfo obiekt.
string monthName = CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedMonthName(8)
Dla Pełnych Nazw Miesięcy: "Sierpień"
DateTimeFormatInfo.Metoda GetMonthName (Int32)
Zwraca pełną nazwę specyficzną dla kultury określony miesiąc na podstawie kultura związana z bieżącym obiektem DateTimeFormatInfo.
string monthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(8);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-03-20 00:53:28
Zastąp GetMonthName
przez GetAbbreviatedMonthName
tak aby brzmiało:
string strMonthName = mfi.GetAbbreviatedMonthName(8);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-07-06 08:08:28
Możesz to uzyskać w następujący sposób,
DateTimeFormatInfo mfi = new DateTimeFormatInfo();
string strMonthName = mfi.GetMonthName(8).ToString(); //August
Teraz zdobądź pierwsze trzy znaki
string shortMonthName = strMonthName.Substring(0, 3); //Aug
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2019-10-03 22:57:31
Chcesz GetAbbreviatedMonthName
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-07-06 07:02:13
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(4)
Ta metoda zwraca April
Jeśli potrzebujesz jakiegoś specjalnego języka, możesz dodać:
<system.web>
<globalization culture="es-ES" uiCulture="es-ES"></globalization>
<compilation debug="true"
</system.web>
Lub preferowany język.
Na przykład z es-ES
Kultura:
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(4)
Returns: Abril
Zwraca: Abril
(po hiszpańsku, ponieważ skonfigurowaliśmy culture as es-ES
w naszym pliku webconfig
, w przeciwnym razie otrzymasz April
)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-07-21 14:00:20
To powinno zwracać tekst miesiąca (styczeń-grudzień) z indeksu miesiąca(1-12)
int monthNumber = 1; //1-12
string monthName = new DateTimeFormatInfo().GetMonthName(monthNumber);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2019-01-21 01:45:15
var month = 5;
var cultureSwe = "sv-SE";
var monthSwe = CultureInfo.CreateSpecificCulture(cultureSwe).DateTimeFormat.GetAbbreviatedMonthName(month);
Console.WriteLine(monthSwe);
var cultureEn = "en-US";
var monthEn = CultureInfo.CreateSpecificCulture(cultureEn).DateTimeFormat.GetAbbreviatedMonthName(month);
Console.WriteLine(monthEn);
Wyjście
maj
may
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-02-03 09:15:49
Możesz również to zrobić, aby uzyskać bieżący miesiąc:
string monthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.Now.Month);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-11-22 10:51:38