ุจุณู
ุงููู ุงูุฑุญู
ุงู ุงูุฑุญูู
very simple using string format
on .ToSTring("") :
if you use "hh" โ> Hour, using a 12-hour clock from 01 to 12.
if you use "HH" โ> Hour, using a 24-hour clock from 00 to 23.
if you add "tt" โ> Designation Am / Pm.
conversion example from 23:12 to 11:12 Pm:
DateTime d = new DateTime(1, 1, 1, 23, 12, 0); var res = d.ToString("hh:mm tt"); // this show 11:12 Pm var res2 = d.ToString("HH:mm"); // this show 23:12 Console.WriteLine(res); Console.WriteLine(res2); Console.Read();
Wait a second, that not all you need to take care of something else is the Culture system, because the same code is executed in windows with a different langage especialy with a different culture langage will generate an excellent result with the same code
An example of windows installed in an Arabic language culture would look like this:
// 23: 12 ู
ู
means Evening (first leter of ู
ุณุงุก).
in another system culture it depends on what is set on the regional and language options of Windows, it will display // 23:12 du.
you can change between different formats on the Windows control panel under regional and language versions of Windows โ the current format (combobox) and change ... apply it, rebuild (execute) your application and see what iam is talking about.
so who can I make Am and Pm show in English if the culture of the current system is not installed in English?
easy by simply adding two lines: โ
the first step is to add using System.Globalization; on top of your code
and a modification of the previous code will look like this:
DateTime d = new DateTime(1, 1, 1, 23, 12, 0); var res = d.ToString("HH:mm tt", CultureInfo.InvariantCulture);
InvariantCulture => using the standard English format.
One more question: do I want pm to be in Arabic or a specific language, even if I use Windows installed in a regional (or other language) regional format?
Soution for Arabic Exemple:
DateTime d = new DateTime(1, 1, 1, 23, 12, 0); var res = d.ToString("HH:mm tt", CultureInfo.CreateSpecificCulture("ar-AE"));
it will show // 23:12 ู
if my system is set to English. you can change "ar-AE" if you want to use a different format. There is a list of each language and its format.
examples: ar ar-SA Arabic ar-BH ar-BH Arabic (Bahrain) ar-DZ ar-DZ Arabic (Algeria) ar-EG ar-EG Arabic (Egypt)
...
Make me know that you have another question.