Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, November 19, 2010 8:55 AM
Hi,
In my sample application i have one combo box and one textblock, in combo box i am displaying all time zones, in textblock i am displaying current date by default that would be in en-US format. But my indention is whenever i change time zone in that combo box, that coresponding timezone's date formate should be display in that Date's textblock. Here i attached my sample code. pls help me to achieve this feature.
Is any possibility there to take corresponding culture info based on the selected timezone?
namespace WpfApplication2
{
/// <summary>
/// Interaction logic for TimeZoneDemo.xaml
/// </summary>
public partial class TimeZoneDemo : Window
{
private ObservableCollection<TimeZone> timeZones;
public TimeZoneDemo()
{
InitializeComponent();
timeZones = new ObservableCollection<TimeZone>();
ReadOnlyCollection<TimeZoneInfo> tzCollection = TimeZoneInfo.GetSystemTimeZones();
foreach (TimeZoneInfo tz in tzCollection)
{
timeZones.Add(new TimeZone() { TimeZoneId = tz.Id.ToString(), Title = tz.DisplayName });
}
cmbTimeZone.ItemsSource = timeZones;
txtDate.Text = DateTime.Now.ToString("D", CultureInfo.GetCultureInfo("en-US"));//ru-RU
}
private void cmbTimeZone_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
}
public class TimeZone
{
public string TimeZoneId { get; set; }
public string Title { get; set; }
}
}
All replies (3)
Friday, November 19, 2010 12:18 PM âś…Answered
Hmm, I cannot follow you.
Where do you see different IDs for each city? I just see, what you also pasted there - the Id "W. Europe Standard Time" with DisplayName that contains all these cities.
So there is no way to just take the timezone and say: You get de-DE. That would make any others angry I fear. And I also fear that an it-Culture would only make italian guys happy.
But what I also wrote in a short note but didn't explain: Timezone simply means the geographic region where you are located - which is an area that goes more or less from the north pole to the south pole! And the culture is something, that has to do with the culture of the user.
Switzerland is a very good example. In there you find people who want to speak this switzer-Deutsch (de-CH I think), but switzerland can be parted a little. The part near italy might have a lot of people who could like an it-culture instead. Or people near france an fr-culture!
And of course: People moving around the world. So people want to keep their culture (I do not know how people in the US write their dates and so when I just came there!) but of course they want to change their timezone (I want to be able to commit to a meeting and the software should show me "Local time: 10:00 - 10:30" automatically! I do not want to be there to early or to late!)
So in my eyes timezone and culture are not connected.
(And when you check the TimeZoneInfo and TimeZone classes, you will also be unable to find any connection.)
I hope that made it a little clear.
With kind regards,
Konrad
Friday, November 19, 2010 9:13 AM | 1 vote
There is no 1:1 relationship between a timezone and a culture.
So I am in the timezone UTC +01:00 and the fllowing cities are shown to me from Windows 7: Amsterdam (Netherlands), Berlin (Germany), Bern (Switzerland), Rom (Italy) Stockholm (Sweden), Wien (Austria)
So which culture do you want to choose?
And another topic: Maybe I would like to keep a de-DE setting when I travel to the US? So my timezone will be a US timezone for some time but I would be very angry if you force me to use en-US which I do not like to have.
I hope you understand, what problems I saw.
With kind regards,
Konrad
Friday, November 19, 2010 11:56 AM
Hi Konrad,
You are saying, it (UTC +01:00) have lot of cities, but every one have it's own time zone id, like below. Is any possibility there to take that corresponding time zone id's culture info(en-US).
W. Europe Standard Time--(UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna
Central Europe Standard Time--(UTC+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague
Regards
UdayaKumar S