daylight.start

I need to get the start and end dates for daylight savings time throughout the world.

I can use daylight.start and daylight.nd to get my local dates. From what I found out is that these routines use timezone.xxx

which is normally timezone.local. Does anyone know how I can change timezone.local to a differant country within basic or another way I can get these dates?

Thanks

[400 byte] By [ttfo] at [2007-12-28]
# 1
ttfo wrote:

I need to get the start and end dates for daylight savings time throughout the world.

I can use daylight.start and daylight.nd to get my local dates. From what I found out is that these routines use timezone.xxx

which is normally timezone.local. Does anyone know how I can change timezone.local to a differant country within basic or another way I can get these dates?

Thanks

Hi,

From this thread.>>

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=552458&SiteID=1

The user "ALEX MS VB QA" talks of setting the current locale.

Try doing this at the start of your program.

Maybe you need to do that to get the various results you want.

Regards,

S_DS.

P.S.

See also.>>

Alex MS VB QA wrote:

System.Threading.Thread.CurrentThread.CurrentCulture = _

New System.Globalization.CultureInfo("en-us")

That said, I'd like to make a couple of points - locales are used to determine what conversions do when going from string to decimal and vice versa, since the text is assumed to be wanted to be intelligible by the local user - won't your danish users type 22,50 for the latitude information?

You may want to leave the current thread's locale as per the local settings, and either just change it to write data files to disk, or use non text formats when writing to disk. Non text formats are independent of the locale.




Alex MS VB QA

Spidermans_DarkSide at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

Thanks for the reply,

I am not familar with the cultralinfo, from what I read, it sounds like it should work.

I tried :

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-gb")

Dim ft As String

Dim localZone As TimeZone = TimeZone.CurrentTimeZone

Dim daylight As DaylightTime = _

localZone.GetDaylightChanges(2007)

localZone.GetDaylightChanges(2007)

TBPassedParms.Text = daylight.Start

I still get the local DST dates. What am I doing wrong?

Thanks

ttfo at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3

Hi

You could get your code working with a little tweak ....

Dim ci As CultureInfo = New System.Globalization.CultureInfo("en-gb")

Thread.CurrentThread.CurrentCulture = ci

ci.ClearCachedData

Just ensure that you set the culture back to what it should be and clear the cache before you finish.

It should be noted that the DateTime structure represents a point in time on the gregorian calendar and that some of its methods use the local culture whilst others do not.

Hope this gets you up and running.

Richard

PS .. useful link http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/datetimecode.asp

DickDonny at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4

Richard,

Thanks for the reply. I added your code, but now I get:

<IPermission class="System.Security.Permissions.SecurityPermThe program '[1964] WindowsApplication1.exe' has exited with code 0 (0x0).

ission, mscorlib, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

version="1"

Flags="ControlThread"/>

Been looking, but can't find what caused this.

Thanks

ttfo at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5

Nevermind the previous post for security. found the problam and fixed it.

Now I will test your suggestion.

will let you know.

Thanks

ttfo at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 6

I have done some testing and I get the same date for every country, but the date format does change to the country I picked. But I still need the DST for that country. Did I do this correctly?

Dim ci As CultureInfo = New System.Globalization.CultureInfo("de-DE")

System.Threading.Thread.CurrentThread.CurrentCulture = ci

Dim localZone As TimeZone = TimeZone.CurrentTimeZone

Dim daylight As DaylightTime = localZone.GetDaylightChanges(2007)

ci.ClearCachedData()

dst.Text = daylight.Start

Tony

ttfo at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 7

Hi Tony

Sorry about that, I should have checked the suggested code a little closer.

I've spent some time looking into this today (I will have to same thing to tackle on a new project soon) and it all seems to be a bit of a mess.

The DateTime type represents and instance in time and some of its methods consider the locale on the current thread (tostring etc) and some do not. This we already knew.

If we check the typename of TimeZone.CurrentTimeZone we get back CurrentSystemTimeZone.

If we check the framework code, we find this is an internal class definition that seems to hook into the locale on your windows system and not on the active thread. In short, useless for what you (and I) want to do.

The good news is that the Orcas release of the framework include a TimeZone2 class that handles these types of issues natively. I've had a quick look at it and it hooks into the registry to get all sorts of locale information.

I'll dig some more and get back to you when I have a workable solution.

Richard

DickDonny at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 8

Richard,

Thank for all the work. I too have spent a bunch of time investigating. The only thing I found was to change the registry on the client each time. I didn't like that idea. I hope one of us finds a good soultion.

Thanks

ttfo at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...