Timezone and time API problem (.net bug!?)

  • Thread starter Thread starter Raj Chudasama
  • Start date Start date
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.

They are two different classes (TimeZone and DateTime), so you can't
extrapolate the behaviour from DateTime to TimeZone.

My guess is that the value behind the static property CurrentTimeZone is
defined as a static variable itself, and assigned "at first use" of TimeZone
in your application.



// Bjorn A
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top