Click here to Skip to main content
15,881,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,

I'm trying to create a very simple WPF Application that when a button is hit will print out the date and time that is located on that button. For instance pressing"Get UK Time" will run the event handler, and put that time in a text box.

I've looked at the DateTime object classes, but I don't see any support for other time zones.

Do I need to manually add the hours into some code somewhere, or is there an easier way to do this?
Posted
Comments
Philippe Mori 16-Sep-14 19:44pm    
As indicated in solution 1,.NET Framework as a good support for time zone (those that you can select in control panel).

By the way, the framework properly handle converting time using appropriate daylight for the time you try to convert and also properly handle overlappping time when the clock is moved back an hour and it knows rules for different countries.

try this

C#
private void Form1_Load(object sender, EventArgs e)
{
   ReadOnlyCollection<timezoneinfo> tzCollection; 
   tzCollection = TimeZoneInfo.GetSystemTimeZones();
   this.timeZoneList.DataSource = tzCollection;
}

private void OkButton_Click(object sender, EventArgs e)
{
   TimeZoneInfo selectedTimeZone = (TimeZoneInfo) this.timeZoneList.SelectedItem;
   MessageBox.Show("You selected the " + selectedTimeZone.ToString() + " time zone.");
}
</timezoneinfo>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900