Collect day and month names of a culture in C#

The CultureInfo class helps you get the names of days and months in various languages that belong to the selected culture.

Here come 2 simple functions to collect the day and month names in string lists:

public List<string> GetWeekDaysByCulture(CultureInfo culture)
{
	return new List<string>
	{
									
		culture.DateTimeFormat.GetDayName(DayOfWeek.Monday), 
		culture.DateTimeFormat.GetDayName(DayOfWeek.Tuesday), 
		culture.DateTimeFormat.GetDayName(DayOfWeek.Wednesday), 
		culture.DateTimeFormat.GetDayName(DayOfWeek.Thursday), 
		culture.DateTimeFormat.GetDayName(DayOfWeek.Friday), 
		culture.DateTimeFormat.GetDayName(DayOfWeek.Saturday), 
		culture.DateTimeFormat.GetDayName(DayOfWeek.Sunday)
	};
}

public List<string> GetMonthNamesByCulture(CultureInfo culture)
{
	return new List<string>
	{
		culture.DateTimeFormat.GetMonthName(1),
		culture.DateTimeFormat.GetMonthName(2),
		culture.DateTimeFormat.GetMonthName(3),
		culture.DateTimeFormat.GetMonthName(4),
		culture.DateTimeFormat.GetMonthName(5),
		culture.DateTimeFormat.GetMonthName(6),
		culture.DateTimeFormat.GetMonthName(7),
		culture.DateTimeFormat.GetMonthName(8),
		culture.DateTimeFormat.GetMonthName(9),
		culture.DateTimeFormat.GetMonthName(10),
		culture.DateTimeFormat.GetMonthName(11),
		culture.DateTimeFormat.GetMonthName(12),
	};
}

You can call these functions as follows to get the French day and month names:

List<string> days = GetWeekDaysByCulture(new CultureInfo("fr-FR"));
List<string> months = GetMonthNamesByCulture(new CultureInfo("fr-FR"));

days.ForEach(d => Debug.WriteLine(d));
Debug.WriteLine("=====================");
months.ForEach(m => Debug.WriteLine(m));

Here’s the output:

lundi
mardi
mercredi
jeudi
vendredi
samedi
dimanche
=====================
janvier
février
mars
avril
mai
juin
juillet
août
septembre
octobre
novembre
décembre

Now you know the day and month names in French.

Read all posts related to Globalisation in .NET here.

Advertisements

About Andras Nemes
I'm a .NET/Java developer living and working in Stockholm, Sweden.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

ultimatemindsettoday

A great WordPress.com site

Elliot Balynn's Blog

A directory of wonderful thoughts

Robin Sedlaczek's Blog

Developer on Microsoft Technologies

HarsH ReaLiTy

A Good Blog is Hard to Find

Softwarearchitektur in der Praxis

Wissenswertes zu Webentwicklung, Domain-Driven Design und Microservices

the software architecture

thoughts, ideas, diagrams,enterprise code, design pattern , solution designs

Technology Talks

on Microsoft technologies, Web, Android and others

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

Anything around ASP.NET MVC,WEB API, WCF, Entity Framework & AngularJS

Cyber Matters

Bite-size insight on Cyber Security for the not too technical.

Guru N Guns's

OneSolution To dOTnET.

Johnny Zraiby

Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

%d bloggers like this: