PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Time Zone Class-VBForums
Results 1 to 12 of 12

Thread: Time Zone Class

  1. #1

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Time Zone Class

    Last updated: 09/24/2007

    Some times I update the component and post the updated date and the assembly version number so it is recommended to check it once a while.

    As all we know .Net’s (up to framework 2) Time Zone class is not much of use since it only gives as objects that are associate with the current time zone, therefore I decided to create a time zone class and called it TimeZoneInfo that can give us information and methods for the other time zones as well. Mainly TimeZoneInfo class uses the windows registry information under the key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\Time Zones” so it is critical that the registry includes the latest updates from MS.
    The class provides all the information and the functionality for the time zones. For example it provides Daylight Saving Time dates for the time zone, Current UtcOffset, Current Time, Current System Time Zone etc.

    Using the Class:
    vb Code:
    1. 'Get all time zones on the system and show them in a ListBox control
    2.  Me.ListBox1.DataSource = TimeZoneInfo.GetTimeZones
    vb Code:
    1. Dim tzInfo As TimeZoneInfo
    2.  'Create new instans of a TimeZoneInfo for a specific time zone.
    3.  tzInfo = New TimeZoneInfo("Pacific Standard Time")
    4.  'Or
    5.  tzInfo = TimeZoneInfo.FromStandardName("Pacific Standard Time")
    6.  'Get the current UtcOffset of the time zone
    7.  Dim utcOffset As TimeSpan = tzInfo.CurrentUtcOffset
    8.  'Get the current time of the time zone
    9.  Dim time As DateTime = tzInfo.CurrentTime
    10.  'Get a value specifing if it is a dailight saving time currently for the time zone
    11.  Dim isDaylight As Boolean = tzInfo.IsDaylightSavingTime
    12.  'Get dailight changes of the time zone
    13.  Dim dStart, dEnd As DateTime
    14.  Dim dt As System.Globalization.DaylightTime
    15.  dt = tzInfo.GetDaylightChanges(2007)
    16.  dStart = dt.Start
    17.  dEnd = dt.End
    18.  
    19.  'And much more
    20.  '...
    21.  '...
    The class should work on 98/windows NT/2000/XP, but I am not sure if it will work on Vista. Please notify me about the results if you tried it on the other windows than XP.

    Update History:
    09/04/2007 -- Original version.
    09/17/2007 -- (Some internal minor changes to optimize the Sort functionality).
    09/21/2007 -- (A small bag fix).
    09/24/2007 -- (The CurrentTimeZone property of TimeZoneInfo was not getting the correct system current time zone after changing it in the code. This was happening because the .Net TimeZone.CurrentTimeZone has a bug and the TimeZoneInfo class was using this property of TimeZone to return the current system time zone. Now the class implements its own method by using GetTimeZoneInformation Api function which returns the correct system current time zone.
    There are also some changes to the IsDaylightSavingTime and GetDaylightChanges functions to optimize and fix some small bugs.)
    Please feel free to rate this post , comment and notify me about any problem associated with it.
    Attached Files Attached Files

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Time Zone Class

    In accordance with this CodeBank policy regarding attachments, your Time Zone Information Demo zip file has been edited and all compiled code has been removed.

    Please do not include any compiled files in your attachments.

    Thank you.

  3. #3

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Time Zone Class

    Quote Originally Posted by Hack
    In accordance with this CodeBank policy regarding attachments, your Time Zone Information Demo zip file has been edited and all compiled code has been removed.

    Please do not include any compiled files in your attachments.

    Thank you.
    Hi Hack, I thought it is ok to include compiled file for the people to try the demo of the class if the project is included. If it is a new policy than I think it doesn’t make since to post any demo project at all. I will remove the demo project since there is no reason for it to be posted.
    Best regards,
    VBDT

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,793

    Re: Time Zone Class

    It's always been the case.... Why doesn't it make sense to post a demo project, but makes sense to post a compiled demo? Doesn't that defeat the purpose? I want to see how it's used... not just that it can do x and y. Otherwise it's like: Ok, great, it does x and y. But HOW do I call X and Y?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Time Zone Class

    Actually, I posted the entire demo project with its compiled .exe files initially. but, I think I misunderstood Hack my apologies. I see your point now, but I think if the person worries about getting viruses they can simply run the project instead of the exe file. Anyway, I posted the demo project again without the compiled files

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Time Zone Class

    As techgnome stated, this has always been a policy. However, it was an unwritten one until I put the policy in writing and it became an official part of CodeBank posting.

    If you will notice the date of the sticky thread which details this policy, you will see that is been officially in place since May of 2005.

    The main reason is so that people don't have to worry about getting virus because there aren't any compiled files to get them from.

  7. #7
    New Member HijodePuta's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    2

    Cool Re: Time Zone Class

    Hi VBDT,

    I have Windows Vista Ultimate and Microsoft Visual Basic 2005 on my pc. I am new in programming and I am very interested with your post regarding Time Zone Class. It seems that i can't run the demo project though. I am currently playing around VB.Net and came accross to this thread. And it seems that you are the only one around the world that posted a thread regarding Time Zones using VB.Net and I am truly fortunate to find it.

    Well, I am attempting to create a VB.Net program that would just display the Current Time on the computer with different Time Zone equivalents.

    Example Output:

    Current Time: 11:13 PM

    Equivalent to:

    EST = 11:13 PM
    CST = 10:13 PM
    MST = 09:13 PM
    PST = 08:13 PM

    I would appreciate any help from you guys.

    Thanks.

    HijodePuta

  8. #8

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Time Zone Class

    Quote Originally Posted by HijodePuta
    Hi VBDT,

    I have Windows Vista Ultimate and Microsoft Visual Basic 2005 on my pc. I am new in programming and I am very interested with your post regarding Time Zone Class. It seems that i can't run the demo project though. I am currently playing around VB.Net and came accross to this thread. And it seems that you are the only one around the world that posted a thread regarding Time Zones using VB.Net and I am truly fortunate to find it.

    Well, I am attempting to create a VB.Net program that would just display the Current Time on the computer with different Time Zone equivalents.

    Example Output:

    Current Time: 11:13 PM

    Equivalent to:

    EST = 11:13 PM
    CST = 10:13 PM
    MST = 09:13 PM
    PST = 08:13 PM

    I would appreciate any help from you guys.

    Thanks.

    HijodePuta
    To run the demo project you need to download the zip file, unzip it and debag it with VS 2005.

    The TimezoneInfo class is designed for up to Win Xp and I am not sure if it will work with vista since ms has changed a lit bit the registry keys of vista, but you can try and see if it works. From there I will see if I can help you.

  9. #9
    New Member HijodePuta's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    2

    Re: Time Zone Class

    Thanks for the reply VBDT. Yes the demo did work.

  10. #10
    New Member
    Join Date
    Nov 2007
    Posts
    3

    Re: Time Zone Class

    Thanks

  11. #11
    New Member
    Join Date
    Jun 2008
    Posts
    1

    Re: Time Zone Class

    this is a great post. can any body if i use this class and bind it to a drop down list in vb.net and user makes a selection so how can i pass the selection from dropdown to timezone info class as standard name i am asking this because
    if dlst.selectedvalue ="(GMT-5:00) Eastern Time (US & Canada)"
    how can you convert it in the constructor of time zone class to "Easter standard time"
    if you refer it in
    tzinfo = New TimeZoneInfo (Cstr(dlst.selectedValue).Tostring) gives an error that it can not convert a string to timezone info object. would any body know who do i need to change in the timezoneinfo class to have it read the selection in a drop down in standard format or other suggestions are welcome

  12. #12

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Time Zone Class

    Quote Originally Posted by oqmalik
    this is a great post. can any body if i use this class and bind it to a drop down list in vb.net and user makes a selection so how can i pass the selection from dropdown to timezone info class as standard name i am asking this because
    if dlst.selectedvalue ="(GMT-5:00) Eastern Time (US & Canada)"
    how can you convert it in the constructor of time zone class to "Easter standard time"
    if you refer it in
    tzinfo = New TimeZoneInfo (Cstr(dlst.selectedValue).Tostring) gives an error that it can not convert a string to timezone info object. would any body know who do i need to change in the timezoneinfo class to have it read the selection in a drop down in standard format or other suggestions are welcome
    Try this
    vb Code:
    1. Dim tzi As TimeZoneInfo
    2. tzi = CType(yourDropDownList.SelectedItem, TimeZoneInfo)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width