R
Raj Chudasama
I have the following code for a clock in my gui.
Everything works fine EXCEPT the following line when the TimeZone is changed
in the windows.
string tz = TimeZone.CurrentTimeZone.StandardName;
It will not pick the changed timezone
but it does pick up time change due to timezone change.
Should it not update the timezone each time the timer ticks? the time does.
However, if i restart the application the new timezone is picked up.
BTW Anyone have a better way to format the time?
sorry i am noob
private void ClockTimer_Tick(object sender, EventArgs e)
{
int hour=DateTime.Now.Hour;
int min=DateTime.Now.Minute;
int sec=DateTime.Now.Second;
string TimeInString =(hour < 10)?"0" + hour.ToString() :hour.ToString();
TimeInString+=":" + ((min<10)?"0" + min.ToString() :min.ToString());
TimeInString+=":" + ((sec<10)?"0" + sec.ToString() :sec.ToString());
string tz = TimeZone.CurrentTimeZone.StandardName;
string[] temp = tz.Split(' ');
if(temp.Length >=3)
lblClock.Text = TimeInString + " " +temp[0][0] + temp[1][0] + temp[2][0];
else
lblClock.Text = TimeInString;
}
Everything works fine EXCEPT the following line when the TimeZone is changed
in the windows.
string tz = TimeZone.CurrentTimeZone.StandardName;
It will not pick the changed timezone
but it does pick up time change due to timezone change.
Should it not update the timezone each time the timer ticks? the time does.
However, if i restart the application the new timezone is picked up.
BTW Anyone have a better way to format the time?

private void ClockTimer_Tick(object sender, EventArgs e)
{
int hour=DateTime.Now.Hour;
int min=DateTime.Now.Minute;
int sec=DateTime.Now.Second;
string TimeInString =(hour < 10)?"0" + hour.ToString() :hour.ToString();
TimeInString+=":" + ((min<10)?"0" + min.ToString() :min.ToString());
TimeInString+=":" + ((sec<10)?"0" + sec.ToString() :sec.ToString());
string tz = TimeZone.CurrentTimeZone.StandardName;
string[] temp = tz.Split(' ');
if(temp.Length >=3)
lblClock.Text = TimeInString + " " +temp[0][0] + temp[1][0] + temp[2][0];
else
lblClock.Text = TimeInString;
}