To globalize an application, there are several steps I'll show you in a
demo, but at a high level, first, it's necessary to set the current culture
using the CultureInfo as I showed you earlier.
Then, using the CurrentCulture,
you show information in specific formats related to the
region where the code is going to be executed.
For example, format dates or currency values.
You can pass culture as an argument for this to take place. In
this example, I call ToString and pass the CultureInfo for how
the date needs to be formatted.
Let me show you globalization with a demo. In this globalization
demo, I'll show you three different demos,
one for the calendar,
the other one for the datetime, and the third one with a currency.
Let me show you the calendar first. In this one, I'm going
to create CultureInfo object, and I'm going to create a
specific culture, Chinese‑Taiwan.
Also, I'll define a date, January 16, 2022. First, I'll display the
date using the default that's the Gregorian calendar.
The Gregorian calendar is a calendar used in most of the world.
It's been in place since 1582.
It's the one where we have 365 days every year, and
every 4 years there's a leap day.
That is when February has one more day.
The date looks like this, 2022/1/16. And now I'm going to change the
current calendar and display the date, but using the Taiwan calendar. I
make the assignment, and then I output 111/1/16.
So, what does 111 mean? Without getting into any religion, 2022, it's related
to AD, the Anno Domini, which is related to Christianity.
The 111 is related to the Republic of China calendar, or Minguo calendar.
This calendar uses 1912 as the year of establishment of
the Republic of China as its first year.
And so you can set different calendars to globalize your application like this.
Let's go see the dates. Now, I'll set a new DateTime.
This includes the date, which is June 1, 2022 at 4:37 PM.
I'll show you this state formatted for the US, France, and Germany. So
basically, for each one of the cultures in this CultureInfo array, I'll
just do a dateValue.ToString and pass the culture as parameter. This is
en‑US, starts with the month, then the day,
year, and then 4:37 PM, meaning post meridiem; that's afternoon.
Then for France, it goes with the day first, then month, then year and 16:37.
There's no PM or AM.
They basically used the 24‑hour format.
It's very similar for Germany, just that they used a period instead of
the forward slash for the date. And now let's do the currency. I'll
create this value, which is a double, 1634 with 92 cents, basically.
I'll create a new CultureInfo object for French‑Canada, and then I'll
output the formatted value. In Canada, they use the dollar sign on the
right, they use a space for the thousands, and a comma for the decimal.
Next up, if I do this for the US, you will see that in the US
a comma is used for the 1000 separator and a period for the
decimals. Which if I do for China,
the format is similar, but they don't use the dollar sign.
And with this, I've showed you how you can use globalization to format the dates, the time and the currency.