Figuring out daylight saving time?

L

Lothar Behrens

Hi,

I played with the following code in my project and figured out that
when the application is not restarted and I change the date from
26.01.2011 to 20.07.2011 the code does not change the label to
indicate summer time.

Only after I restart the application, the change is recognized.

Why does this not work while the application keeps running?

private void button1_Click(object sender, EventArgs e)
{
if (DateTime.Now.IsDaylightSavingTime())
label1.Text = "It is daylight saving time";
else
label1.Text = "It is not daylight saving time";
}

Thanks,

Lothar
 
L

Lothar Behrens

Hi,

I played with the following code in my project and figured out that
when the application is not restarted and I change the date from
26.01.2011 to 20.07.2011 the code does not change the label to
indicate summer time.

Only after I restart the application, the change is recognized.

Why does this not work while the application keeps running?

        private void button1_Click(object sender, EventArgs e)
        {
            if (DateTime.Now.IsDaylightSavingTime())
                label1.Text = "It is daylight saving time";
            else
                label1.Text = "It is not daylight saving time";
        }

Thanks,

Lothar

It seens only sometimes not be correct. I don't know why this happens.
 
A

Arne Vajhøj

It seens only sometimes not be correct. I don't know why this happens.

Do you restart the app after changing date?

Do you restart Windows after changing date?

One obvious explanation would be that some information is cached
somewhere either in .NET or Windows.

Arne
 

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

Top