By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,491 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,491 IT Pros & Developers. It's quick & easy.

reading time zone information

P: n/a
Hi All

I have a windows application written in VB.net 2005

The users have to select a State of Australia, which I use to check they have the correct windows time zone selected in control panel

Dim myzone As TimeZone = TimeZone.CurrentTimeZone
If they change the Time zone whilst my application is running, a new call to Dim myzone As TimeZone = TimeZone.CurrentTimeZone returns the same time zone NOT the new one

They have to restart my application to get the correct time zone

It appears that the time zone is read by my application on startup and is cached rather than reading directly from Windows each time

How can I get my application to refresh its Time zone value, so the user doesn't have to restart my application, after changing the Windows time zone?

Regards

Steve

Sep 23 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Steve,

As the time zone is changed in your system, then in my opinion it is normally as well the situation in your application, which thinking error is it I am making?

Cor
"Steve" <ga*****@nospam.nospamschreef in bericht news:uf**************@TK2MSFTNGP04.phx.gbl...
Hi All

I have a windows application written in VB.net 2005

The users have to select a State of Australia, which I use to check they have the correct windows time zone selected in control panel

Dim myzone As TimeZone = TimeZone.CurrentTimeZone
If they change the Time zone whilst my application is running, a new call to Dim myzone As TimeZone = TimeZone.CurrentTimeZone returns the same time zone NOT the new one

They have to restart my application to get the correct time zone

It appears that the time zone is read by my application on startup and is cached rather than reading directly from Windows each time

How can I get my application to refresh its Time zone value, so the user doesn't have to restart my application, after changing the Windows time zone?

Regards

Steve

Sep 24 '07 #2

P: n/a
"Cor Ligthert[MVP]" <no************@planet.nlschrieb
Steve,
As the time zone is changed in your system, then in my opinion it is
normally as well the situation in your application, which thinking
error is it I am making?
Cor, In the application, the time zone information is outdated. He changed
it in control panel, but in his code, there is still the old information.

Steve, I don't think this is changable, because, when you think about it:
When does the time zone change while the PC is running? Whenever you are
flying from one zone to the other. This is so rare that it is acceptable to
restart the application, IMO.

Armin

"Steve" <ga*****@nospam.nospamschreef in bericht
news:uf**************@TK2MSFTNGP04.phx.gbl...
Hi All

I have a windows application written in VB.net 2005

The users have to select a State of Australia, which I use to
check they have the correct windows time zone selected in control
panel

Dim myzone As TimeZone = TimeZone.CurrentTimeZone
If they change the Time zone whilst my application is running, a
new call to Dim myzone As TimeZone = TimeZone.CurrentTimeZone
returns the same time zone NOT the new one

They have to restart my application to get the correct time zone

It appears that the time zone is read by my application on
startup and is cached rather than reading directly from Windows
each time

How can I get my application to refresh its Time zone value, so
the user doesn't have to restart my application, after changing
the Windows time zone?

Regards

Steve
Sep 24 '07 #3

P: n/a
Hi Cor

Thanks for the response

When the user changes the time zone in Windows control panel with my application still running, a repeat call to
Dim myzone As TimeZone = TimeZone.CurrentTimeZone
returns the time zone BEFORE they changed it. NOT the new time zone

If they restart my application, the call to Dim myzone As TimeZone = TimeZone.CurrentTimeZone, returns the correct NEW time zone

I need to know how to make my application refresh the time zone from windows

Regards
Steve
"Cor Ligthert[MVP]" <no************@planet.nlwrote in message news:51**********************************@microsof t.com...
Steve,

As the time zone is changed in your system, then in my opinion it is normally as well the situation in your application, which thinking error is it I am making?

Cor
"Steve" <ga*****@nospam.nospamschreef in bericht news:uf**************@TK2MSFTNGP04.phx.gbl...
Hi All

I have a windows application written in VB.net 2005

The users have to select a State of Australia, which I use to check they have the correct windows time zone selected in control panel

Dim myzone As TimeZone = TimeZone.CurrentTimeZone
If they change the Time zone whilst my application is running, a new call to Dim myzone As TimeZone = TimeZone.CurrentTimeZone returns the same time zone NOT the new one

They have to restart my application to get the correct time zone

It appears that the time zone is read by my application on startup and is cached rather than reading directly from Windows each time

How can I get my application to refresh its Time zone value, so the user doesn't have to restart my application, after changing the Windows time zone?

Regards

Steve

Sep 24 '07 #4

P: n/a
Hi Armin

When the users select a 'state of Australia' in my application and try to
save, I compare the State they have selected to the Time zone currently set
in Windows
If it is different, I display a message advising them of the discrepancy and
ask them to either select the correct state OR change the windows time zone
If they minimise my program to go to Control panel to change the Time Zone I
want my application to recognise this and do a new comparison of the Time
zone vs the state of Australia

My application is used Australia wide and I need to ensure each location has
the correct Time Zone set as I use date offsets depending on the location to
ensure dates at Head Office are consistent

regards
Steve

"Armin Zingler" <az*******@freenet.dewrote in message
news:eO*************@TK2MSFTNGP02.phx.gbl...
"Cor Ligthert[MVP]" <no************@planet.nlschrieb
Steve,
>As the time zone is changed in your system, then in my opinion it is
normally as well the situation in your application, which thinking
error is it I am making?

Cor, In the application, the time zone information is outdated. He changed
it in control panel, but in his code, there is still the old information.

Steve, I don't think this is changable, because, when you think about it:
When does the time zone change while the PC is running? Whenever you are
flying from one zone to the other. This is so rare that it is acceptable
to
restart the application, IMO.

Armin

"Steve" <ga*****@nospam.nospamschreef in bericht
news:uf**************@TK2MSFTNGP04.phx.gbl...
Hi All

I have a windows application written in VB.net 2005

The users have to select a State of Australia, which I use to
check they have the correct windows time zone selected in control
panel

Dim myzone As TimeZone = TimeZone.CurrentTimeZone
If they change the Time zone whilst my application is running, a
new call to Dim myzone As TimeZone = TimeZone.CurrentTimeZone
returns the same time zone NOT the new one

They have to restart my application to get the correct time zone

It appears that the time zone is read by my application on
startup and is cached rather than reading directly from Windows
each time

How can I get my application to refresh its Time zone value, so
the user doesn't have to restart my application, after changing
the Windows time zone?

Regards

Steve

Sep 24 '07 #5

P: n/a
Steve wrote:
When the users select a 'state of Australia' in my application and
try to save, I compare the State they have selected to the Time zone
currently set in Windows
If it is different, I display a message advising them of the
discrepancy and ask them to either select the correct state OR change
the windows time zone If they minimise my program to go to Control
panel to change the Time Zone I want my application to recognise this
and do a new comparison of the Time zone vs the state of Australia
I suppose you'll have to look in the registry:
http://vbnet.mvps.org/index.html?cod...onedisplay.htm

Andrew
Sep 24 '07 #6

P: n/a
Hi Steve,

You can make use of the Win32 API function GetTimeZoneInformation in your
application to get the current time zone on the local machine.

The following is a sample.

Imports System.Runtime.InteropServices

Public Class Form1

<StructLayout(LayoutKind.Sequential)_
Public Structure SYSTEMTIME
Public wYear As UInt16
Public wMonth As UInt16
Public wDayOfWeek As UInt16
Public wDay As UInt16
Public wHour As UInt16
Public wMinute As UInt16
Public wSecond As UInt16
Public wMilliseconds As UInt16
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)_
Public Structure TIME_ZONE_INFORMATION
<MarshalAs(UnmanagedType.I4)_
Public Bias As Int32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)_
Public StandardName As String
Public StandardDate As SYSTEMTIME
<MarshalAs(UnmanagedType.I4)_
Public StandardBias As Int32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)_
Public DaylightName As String
Public DaylightDate As SYSTEMTIME
<MarshalAs(UnmanagedType.I4)_
Public DaylightBias As Int32

End Structure

Declare Auto Function GetTimeZoneInformation Lib "kernel32.dll" (ByRef
lpTimeZoneInformation As TIME_ZONE_INFORMATION) As UInt32

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim tziNative As TIME_ZONE_INFORMATION
GetTimeZoneInformation(tziNative)
End Sub
End Class
Hope this helps.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 24 '07 #7

P: n/a
Linda

Thanks

Great help

Regards
Steve

"Linda Liu [MSFT]" <v-****@online.microsoft.comwrote in message
news:CH**************@TK2MSFTNGHUB02.phx.gbl...
Hi Steve,

You can make use of the Win32 API function GetTimeZoneInformation in your
application to get the current time zone on the local machine.

The following is a sample.

Imports System.Runtime.InteropServices

Public Class Form1

<StructLayout(LayoutKind.Sequential)_
Public Structure SYSTEMTIME
Public wYear As UInt16
Public wMonth As UInt16
Public wDayOfWeek As UInt16
Public wDay As UInt16
Public wHour As UInt16
Public wMinute As UInt16
Public wSecond As UInt16
Public wMilliseconds As UInt16
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)_
Public Structure TIME_ZONE_INFORMATION
<MarshalAs(UnmanagedType.I4)_
Public Bias As Int32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)_
Public StandardName As String
Public StandardDate As SYSTEMTIME
<MarshalAs(UnmanagedType.I4)_
Public StandardBias As Int32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)_
Public DaylightName As String
Public DaylightDate As SYSTEMTIME
<MarshalAs(UnmanagedType.I4)_
Public DaylightBias As Int32

End Structure

Declare Auto Function GetTimeZoneInformation Lib "kernel32.dll" (ByRef
lpTimeZoneInformation As TIME_ZONE_INFORMATION) As UInt32

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim tziNative As TIME_ZONE_INFORMATION
GetTimeZoneInformation(tziNative)
End Sub
End Class
Hope this helps.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Sep 26 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.