|
I need it in c# please help me where from I can got
|
|
|
|
|
Hi,
This is Great program,
But I have one problem,
The Windows 7 system Don't Allow me to Change the time zone from the program.
When I click apply,
right away
the system Show The user don't have the right to execute the program
even I give the program to have adminstrator status.
Do you know how to fix it?
Jason
|
|
|
|
|
|
Hey, Came across this solution -- excellent. However, my problem is converting datetime values in one timezone with another -- not just based on CurrentTime. I appreciate there is a solution for .net 3.5 -- however, I am stuck with .net 2.0 -- so need to try to extend this to have some sort of Convert method. Have you considered this or are you aware of a solution for this?
Thanks
|
|
|
|
|
Hi!
The excellent class on operation with TimeZone, but I has faced a problem in changing the current TimeZone.
I use the following code:
Dim TZ() As TimeZoneInfo
Private Sub Timezone(ByVal id As String)
TZ = TimeZoneInfo.GetTimeZones
For Each temp As TimeZoneInfo In TZ
If temp.Id = id Then
TimeZoneInfo.CurrentTimeZone = CType(temp, TimeZoneInfo)
End If
Next
End Sub
In Windows XP all works great, but in Windows Vista and Windows 7 there is an error:
"The client does not possess the necessary rights" though the application I run as Administration. The right complete, but I can not change TimeZone,
any suggestions? Thanks
|
|
|
|
|
Hello, I added the TimeZoneInfo.vb class to my ASP.NET project but it's sending kind of errors like:
Type 'DebuggerDisplay' is not defined.
I imagine it's because of the attribute <DebuggerDisplay("{_displayName}")> _
at the begining of the class.
Another error:
'System.Collections.IComparer' has no type parameters and so cannot have type arguments.
Looks like if I had a different .NET framework but I'm working with VS 2005 and .NET 2.0
If I run your demo project in the same machine, it runs ok.
Can you help me, please ?
Thanks a lot.
BR,
|
|
|
|
|
Hi Xavito,
The problem you are having is because the required namespaces are not imported in ASP.Net project by default. You need to import the namespaces in to your project. I don’t have time right now since I have flight in 5 hours but I will suggest you to look for the required namespaces in the VS dynamic help and identify which namespaces you need to import. Just type the name that VS says it cannot find and on the top of the help there is information what namespace it belongs to. Hope this helps.
Regards,
Arman
|
|
|
|
|
Hi, Arman, thank you very much.
Your advice worked fine for the Compiler directives but TimeZoneInfo keeps sending an error:
'System.Collections.IComparer' has no type parameters and so cannot have type arguments.
Well, I think it's not TimeZone but the interface for IComparer, right ? Is it different in ASP.NET than in Windows Forms ?
Do you have an idea of how to work around this ?
Thanks again.
BR,
|
|
|
|
|
Hi Arman.
I found in Internet that there are two types of IComparer interfaces, one is in the System.Collections namespace and the other is in System.Collections.Generic namespace.
So it should looks like this:
Public Class TimeZoneinfo: Implements System.Collections.Generic.IComparer(Of TimeZoneInfo)
What do you think about it ?
Thanks a lot.
BR,
PS. Have a nice trip, btw.
|
|
|
|
|
Hi sorry for the delay, I just got back. Yes that is the interface that should be referenced.
|
|
|
|
|
How I Can Import the namespaces?
Please I need use this class and I don´t Know how I can import them.
In Addittion VB.NET says that: Type 'List' is Not defined in this line Dim tzInfos As New List(Of TimeZoneInfo) and Type 'KeyNotFoundException' is Not defined in this Throw New KeyNotFoundException("Cannot find the windows registry key (Time Zone).")
Regards
Please excuse me, my english is very poor.
modified on Saturday, May 8, 2010 4:24 PM
|
|
|
|
|
Hi Arman,
Thanks for this class. I was having problems with implementation on non-English versions of Windows. I discovered that I needed to revise your "Compare" function; the comparisons were based on DisplayName which didn't compute so I modified it to use UTC offset instead.
Protected Overridable Function Compare(ByVal x As TimeZoneInfo, ByVal y As TimeZoneInfo) As Integer _
Implements System.Collections.Generic.IComparer(Of TimeZoneInfo).Compare
If x._tzi.bias = y._tzi.bias Then
Return x.StandardUtcOffset.CompareTo(y.StandardUtcOffset)
ElseIf x._tzi.bias > y._tzi.bias Then
Return -1
ElseIf x._tzi.bias < y._tzi.bias Then
Return 1
End If
End Function
Again, thanks for your work on this class.
Regards,
Simster
|
|
|
|
|
Hi Simster,
This is just a hint: If you need to sort the time zones based only on standard UTC offset than you can use
Return x.StandardUtcOffset.CompareTo(y.StandardUtcOffset). There is not need for the If…ElseIf statements. Remove them and leave only this line.
Protected Overridable Function Compare(ByVal x As TimeZoneInfo, ByVal y As TimeZoneInfo) As Integer _
Implements System.Collections.Generic.IComparer(Of TimeZoneInfo).Compare
Return x.StandardUtcOffset.CompareTo(y.StandardUtcOffset)
End Function
Best regards,
Arman
|
|
|
|
|
Hi Arman,
Thanks. That makes sense.
If you are curious to know, it was my binding the data to a combobox that generated the exception on an non-English OS. I wasn't explicitly calling the Compare function.
Simster
|
|
|
|
|
I had a similar problem with a non-English Vista machine, but with the the locale set to English. In this case, the OS was in Spanish-Espanol. The problems is with the CurrentTimeZone property, which ultimately leads to the SetValues function which takes a string name of the key. The problem is seen in the CurrentTimeZone's call to TimeZone.CurrentTimeZone.StandardName. The return in this case is in English: "Central Standard Time (Mexico)". However, when looking in the registry, the string is in Espanol: "Hora estandar central (Mexico)".
This seems to be to be a bug in Windows, given that they localize the registry entries bug then don't provide a universal identifier for looking up the timezone. I will probably just transition to the .net 3.5 class most likely inspired by this code.
Thanks Arman!
|
|
|
|
|
|
Hi Neilio, thanks for the input. I know the .Net 3.5 has TimeZoneInfo class (finally ). This may still be useful for .Net 2.0
Regards,
Arman
|
|
|
|
|
Hi there,
Can i add World map in my form like Time zone tab available in windows XP os in which if i select any GMT time zone, the world map shows the location according to that.
Thanks in advance
Krishnraj
|
|
|
|
|
Hi there, thank you so much for posting this article on this website. I have just one problem, which I need your help with I am trying to load all Time Zones into a dropdownlist control but for some reason I can't get it to display any of the time zones... Do you have any idea of how I can go around that????
I'll be looking forward to hear from you very soon...
Thanks in advance,
Sam
hussam
|
|
|
|
|
Hi Sam, sure I can help you with that but first I would recommend you to download the TimeZoneInfo class from the external link I posted here. The reason is that the link contains the update versions since it is more easy to update there than in Code Project.
For windows forms it is a one line coding, here is an example how to load all time zones into a ComboBox control. Note, every item in the combobox has a data type of TimeZoneInfo object so that it makes even easier for you to show a particular time zone data.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Loads all the time zones into the ComboBox control.
Me.ComboBox1.DataSource = TimeZoneInfo.GetTimeZones
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
'Show the time of the selected time zone.
Me.TimeLabel.Text = CType(Me.ComboBox1.SelectedItem, TimeZoneInfo).CurrentTime.ToLongTimeString
End Sub
End Class
For ASP note every item in the DropDownList has a data type of string not a TimeZoneInfo object so if you want to access the time zone object, than you should get it the same way (TimeZoneInfo.GetTimeZones(x), some x that represents the selected index of the DropDownList).
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Loads all the time zones into the ComboBox control.
For Each tzi As TimeZoneInfo In TimeZoneInfo.GetTimeZones
Me.DropDownList1.Items.Add(tzi.ToString)
Next
End Sub
End Class
I hope this helps
modified on Tuesday, September 16, 2008 2:59 AM
|
|
|
|
|
Thanks for posting this.
A word of caution though. If you are running on XP or WS2003, you'll be fine. But Micorsoft significantly changed the structure of the registry entries for time zone in Vista and the upcoming WS2008. The time zone entries in the registry are undocumented and it is recommended that your applications not depend on them for that reason, especially if your applications depend on an accurate local time. Even in the US, time zone conversion dates can change (as we witnessed this year), and even counties and towns can change their time zone without Microsoft necessarily issuing an update to their registry entries.
I used a similar approach to what is recommended in this article, in my existing web application. It currently runs on Windows Server 2003, but when I upgrade to WS2008 next year, I'll need to re-write the time zone classes. When I do, I will no longer choose to depend on the registry (which will have changed from WS2003) and instead subscribe to a provider for time zone data around the world. That way my app will no longer be dependent on the undocumented registry features, that Microsoft may or may not choose to support in the future.
The better approach would be to subscribe to a time zone data provder, like here: http://www.worldtimeserver.com/time_zone_guide/[^].
Anyways, my 2 cents.
|
|
|
|
|
Actually, the entire system depends on the time zone registry values since the local time is calculated based on this values. If the system doesn’t contain the latest MS updates than the system administrator is responsible for it. And the MS is responsible to provide the updates on the time.
As for time zone registry entries, as far as I know they are the same for windows 98, 2000 and XP. The windows Vista has some two or three more entries. That is why I didn’t mention it in requirements.
Honestly, I would never rely to a third party database for time zone information because they may fail to update it so might MS but than MS has more responsibility to keep windows to operate correctly.
Finally, this class really doesn’t care if the time zones have been changed. All it needs the registry values. If the US government or any government decides to change the time zone dates and the MS updates these changes in the windows registry the class will do the implementation using the new information.
-- modified at 0:46 Wednesday 26th September, 2007
|
|
|
|
|
Actually the TZI information is documented, and is different in XP vs. Vista. Prior to Vista there was no structure for storing historical data of timezone daylight saving time information. I would agree that depending on MS to provide updates for the registry settings seems like a rational approach, however my experience over the last decade shows that MS does not always provide global updates. For example, when Australia modified their 'Summer Time' settings to accomodate hosting an Olympic-like event, sorry can't remember the name, MS only listed it on their site, but did not include it as a update for all. That seems to be a serious flaw, as folks unaware of the change may not have known about the need to update. The general feeling seemed to be, if it isn't in your timezone, then you don't need to update, but that's just plain wrong for folks developing global applications.
The other element is that reliance on the registry leaves application developers too exposed to MS changes without notice. While there is still no single global timezone information source, I suggest developers in the .Net world work towards building solutions that incorporate the Olsen TZ information, http://www.twinsun.com/tz/tz-link.htm[^]
This TZ data store is updated routinely, and much more reliable given world-wide community that contributes to checking and confirming timezone information. Microsoft continues to avoid incoporating it, but others have shown it to be a better methodology and approach to keeping systems in sync.
I applaud the effort, and hope you continue to examine other approaches to the topic.
iwonder
|
|
|
|
|
Well, I haven’t explore the Vista’s time zone registry since I use Windows XP but I can tell that Windows XP has a structure that stores the historical dates of time zones, for example if you check the Dynamic DST registry key of Israel which has the TZI info from year 2003 to 2023 or the New Zealand’s’ from 2006 to 2008. Only time zones that have Dynamic DST registry key have the historical data. I am not sure but I think this is the case for Vista too.
I am well aware of that link you provided and it helped me to design this class with testing the daylight change date values but than again since it is a third party database I won’t use it in my applications. Using database has two major drawbacks. If you include the database with your app than the size of your app gets big, and you need to update the database frequently. If you use internet connection to access to the database then the computer should always have connection, it will slow down the app since it will get the time zone information from the web and again the database should have up to date data.
But using the registry the only drawback would be that MS would not update the information on the time.
Best regards,
VBDT
|
|
|
|
|
The historical timezone ability is not part of the XP O/S default registry TZI class. It was only available if you updated the timezone registry with the vista timezone update, which I did on one of my XP machines. The other standard XP machines don't have it, and neither did XP when the O/S shipped.
I know this as fact because I wrote an application to explore the TZI settings to understand how they worked, and can provide a copy of it to you if you are interested. Always intereseted in this topic.
As for your listed drawbacks, that's a design issue to overcome. I would not recommend using solution that uses an internet connection either. However, I've seen folks develop solutions involving huge database information such as zip codes that have them compiled. I would think a similar solution can be developed for the Olsen TZ timezone data store. As far as it being a 3rd party database, that's not a valid objection for most, but you can stick to it. I'm really not advocating using 3rd party solutions either, what I'd like to see is Microsoft incorporate the TZ database into their O/S like similar to the UNIX/Linux world. I don't know if MS has quite the global membership devoted to timezone updates that the TZ group does. Updates are not a problem either, as using the registry with confidence involves users enbabling auto-updates, which most corporate IT groups do not do. We test before we apply updates to the whole networked install base. Not every MS update can be safely applied.
I think the reluctance by MS to offer a better solution is related to a fear of being sued for any information that could possibly be incorrect, as they were several years ago for having pinpointed an area on their tz map with an incorrect timezone. That's why you don't see the MAP ID being used in the TZI anymore. If you look at the countries that do not use Gregorian date based calendars, the MS registry is still not representive and does not support them well. The inability of the world political entities to agree on a common timezone designation and use of summer time/ daylight saving time, or calendar usage is at the core of the problem though, and no O/S is going to overcome that issue.
Now, I don't have a solution to forward or champion, but I'm just pointing out that reliance on the registry is not exactly without flaws. I do agree that in some cases for certain applications it is the best option available to date. Still I'd like to see better from MS. Even their new Vista O/S has a timezone2 class that is supposed to provide support you've done. Although, I've not used it, I don't have Vista either - it's too flakey still and that's another reason why I look to other areas besides the registry. It's a very complicated issue, though, and your example is a good representation of using it, so I'm not knocking your effort.
Thanks
Phil 'iwonder' Guerra
Mission, KS
Phil 'iwonder' Guerra
|
|
|
|
|