Bambang F. Indarto

The Journey… The Shares

Start to Post In Development

Posted by bfindarto on August 13, 2008

One of my purpose when I start this blog is that I want to use it for self learning. As I do also training in development, I’ll start to write about development.

And I think, it is better to me to start on things that my student asked me. Well, one of the best way to learn is just by try to find solution.  🙂

I remember a few weeks ago, there was a question about how to get month name, or day name from a specific date-time value. Well, one way is, we can create a list (or an array) of month or day names and then relate the names to the the specific date-time value using condition statements (if..else or Which is not too efficient.   🙂

The other way is by using CultureInfo classs from System.Globalization namespace. The CultureInfo class holds culture-specific information, such as the associated language, sublanguage, country/region, calendar, and cultural conventions. This class also provides access to culture-specific instances of DateTimeFormatInfo, NumberFormatInfo, CompareInfo, and TextInfo. These objects contain the information required for culture-specific operations, such as casing, formatting dates and numbers, and comparing strings (MSDN).

Lets try one example.

In this example, I just want to get the name of a specific date (2008/8/12).


So, when I press the button, the month name should appear in the text box.

Dim b As Integer = New Date(2008, 8, 12).Day()
Dim GetNames As New System.Globalization.CultureInfo(“en-US”)
TextBox1.Text = GetNames.DateTimeFormat.GetMonthName(b)

One benefit of using this class is, we can produce names in many language. If I use “en-US” as the culture name, the month name would be in American English. If I use “id-ID“, the month name would be in Indonesian.

en id

You may find the reference in the MSDN about Globalization.CultureInfo class.


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: