Display Multi Country Date And Time In Windows Application Using C#

Today, I am going to show you how to display date and time of multiple countries in your Windows application, using C#.

Just consider here, I am going to display date and time of three countries, with 24-hour and 12-hour range format.

Here, I have added some label for representing the country names. For date column, I have created separate labels and for timing, I have created separate labels.



Then, I have added the timer control in my form to diplay the current running time. Just double click the timer button for writing the code, as shown below.
  1. private void timer1_Tick(object sender, EventArgs e) {  
  2.     label2.Text = DateTime.Now.ToString("hh:mm:ss tt");  
  3.     label10.Text = DateTime.Now.ToString("HH:mm:ss");  
  4.     label7.Text = DateTime.Now.ToString("d-MM-yyyy");  
  5.     label14.Text = DateTime.Now.ToString("d-MM-yyyy");  
  6.     TimeZoneInfo TZI = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");  
  7.     DateTime UK = TimeZoneInfo.ConvertTime(DateTime.Now, TZI);  
  8.     label3.Text = UK.ToString("hh:mm:ss tt ");  
  9.     label11.Text = UK.ToString("HH:mm:ss");  
  10.     label8.Text = UK.ToString("d-MM-yyyy");  
  11.     label16.Text = UK.ToString("d-MM-yyyy");  
  12.     TimeZoneInfo TZIUS = TimeZoneInfo.FindSystemTimeZoneById("Central America Standard Time");  
  13.     DateTime US = TimeZoneInfo.ConvertTime(DateTime.Now, TZIUS);  
  14.     label5.Text = US.ToString("hh:mm:ss tt");  
  15.     label12.Text = US.ToString("HH:mm:ss");  
  16.     label9.Text = US.ToString("d-MM-yyyy");  
  17.     label18.Text = US.ToString("d-MM-yyyy");  
  18. }  
Then, give below code to start the timer on page load.
  1. Timer1.start();  
  2. Timer1.Intervels = 1000; // 1000 = 1 seconds   
From the above code, you can see that I get the Timing Information from the local system and I convert that information to string and display in the Windows Form.

Date and Time String Formats 

For time formats 

For 12-Hours, you can use .......... hh:mm:ss tt
For 24-Hours, you can use .......... HH:mm:ss 

For Date Formats 

d-MM-yyyy ----- 18-04-2017
dd-MMM-yyyy - 18-Mar-2017

And the final output would be like the below screen.

 
X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now