none
Time Zones in C#

    Question

  • How could i populate the various timezones in a dropdown.
    I want to save the timezone selected in database and display when ever the user revisits the application.

    I am this thought :

    I will save all the time zones in a table in backend and each with an Id
    I will populate these timezones in the dropdown and whenever user selects a Timezone, i will save the time zone id in backend.
    And whenever the user revisits then i will populate the information saved in backend

    Sandeep...
    Thursday, November 20, 2008 6:19 AM

Answers

  •  
    1 using System;  
    2  
    3 namespace ConsoleApplication1 {  
    4     class Program {  
    5         static void Main(string[] args) {  
    6             foreach (TimeZoneInfo tzi in TimeZoneInfo.GetSystemTimeZones()) {  
    7                 Console.WriteLine(tzi.ToString());  
    8             }  
    9  
    10             Console.ReadLine();  
    11         }  
    12     }  
    13

    TimeZoneInfo.GetSystemTimeZones() returns all the times zones.
    Ron Whittle - If the post is helpful or answers your question, please mark it as such.
    • Marked as answer by Harry Zhu Monday, November 24, 2008 3:29 AM
    Thursday, November 20, 2008 7:33 AM
  • Sandeep Reddy Pinniti said:

    TimeZoneInfo is available in 3.5 framework

    Do we have any equivalent in .net 2.0 Framework
    Please help me


    Sandeep...



    Unfortunately, there is no equivalent in the 2.0 Framework.  You'll either have to upgrade your application to 3.5 or find some other way to solve the problem.
    David Morton - http://blog.davemorton.net/
    • Marked as answer by Harry Zhu Monday, November 24, 2008 3:29 AM
    Thursday, November 20, 2008 2:23 PM
    Moderator
  • Sandeep Reddy Pinniti said:

    TimeZoneInfo is available in 3.5 framework

    Do we have any equivalent in .net 2.0 Framework
    Please help me


    Sandeep...



    Try the thread below for code sample you can use with .NET 2.0 application.

    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/6d47f707-042c-4642-a8af-a52abeafceb4


    Asp.net MVP, MCPD Web C#, MCTS TFS, MCITP BI and DBA
    • Marked as answer by Harry Zhu Monday, November 24, 2008 3:30 AM
    Thursday, November 20, 2008 3:50 PM
    Moderator
  •  Use MS API: Time Zone Editor.
    AlexB
    • Marked as answer by Harry Zhu Monday, November 24, 2008 3:30 AM
    Friday, November 21, 2008 4:00 AM

All replies

  •  
    1 using System;  
    2  
    3 namespace ConsoleApplication1 {  
    4     class Program {  
    5         static void Main(string[] args) {  
    6             foreach (TimeZoneInfo tzi in TimeZoneInfo.GetSystemTimeZones()) {  
    7                 Console.WriteLine(tzi.ToString());  
    8             }  
    9  
    10             Console.ReadLine();  
    11         }  
    12     }  
    13

    TimeZoneInfo.GetSystemTimeZones() returns all the times zones.
    Ron Whittle - If the post is helpful or answers your question, please mark it as such.
    • Marked as answer by Harry Zhu Monday, November 24, 2008 3:29 AM
    Thursday, November 20, 2008 7:33 AM
  • TimeZoneInfo is in System namespace.

    I added System Namespace.
    even though i am getting this error

    The type or namespace name 'TimeZoneInfo' does not exist in the namespace 'System' (are you missing an assembly reference?)   

    My Code is in this way:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;

    namespace TimeZones {
        public partial class Form1 : Form {
            public Form1() {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e) {
                 foreach (System.TimeZoneInfo tzi in TimeZoneInfo.GetSystemTimeZones()) { 
                         Console.WriteLine(tzi.ToString()); 
                     } 
            }
        }
    }

    Sandeep...
    Thursday, November 20, 2008 9:07 AM
  • TimeZoneInfo is available in 3.5 framework

    Do we have any equivalent in .net 2.0 Framework
    Please help me

    Sandeep...
    Thursday, November 20, 2008 9:35 AM
  • Sandeep Reddy Pinniti said:

    TimeZoneInfo is available in 3.5 framework

    Do we have any equivalent in .net 2.0 Framework
    Please help me


    Sandeep...



    Unfortunately, there is no equivalent in the 2.0 Framework.  You'll either have to upgrade your application to 3.5 or find some other way to solve the problem.
    David Morton - http://blog.davemorton.net/
    • Marked as answer by Harry Zhu Monday, November 24, 2008 3:29 AM
    Thursday, November 20, 2008 2:23 PM
    Moderator
  • Sandeep Reddy Pinniti said:

    TimeZoneInfo is available in 3.5 framework

    Do we have any equivalent in .net 2.0 Framework
    Please help me


    Sandeep...



    Try the thread below for code sample you can use with .NET 2.0 application.

    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/6d47f707-042c-4642-a8af-a52abeafceb4


    Asp.net MVP, MCPD Web C#, MCTS TFS, MCITP BI and DBA
    • Marked as answer by Harry Zhu Monday, November 24, 2008 3:30 AM
    Thursday, November 20, 2008 3:50 PM
    Moderator
  •  Use MS API: Time Zone Editor.
    AlexB
    • Marked as answer by Harry Zhu Monday, November 24, 2008 3:30 AM
    Friday, November 21, 2008 4:00 AM
  • AlexBB,

    If the editor in the links below is what you are telling the user then it is not valid when the data is coming from a database Timezone which is ANSI SQL Time Interval new to SQL Server 2008.

    http://support.microsoft.com/default.aspx/kb/914387

    http://blogs.msdn.com/deva/archive/2008/07/12/dst-series-how-to-manually-configure-daylight-saving-time-dates-by-modifying-an-existing-time-zone.aspx





    Asp.net MVP, MCPD Web C#, MCTS TFS, MCITP BI and DBA
    Friday, November 21, 2008 6:07 PM
    Moderator
  •  Caddre, I don't understand why you came up with all that. I am talking about tzEdit.exe a time zone editor which is a part of Windows Resource Kit. I incorporated it into one of my apps for no real purpose: just a nice tool. For demonstration purposes like for this dispute I open it and  see a complete ListBox of ALL world time zones with my timeZone highlighted. It means that the API detects the computer's timezone.
    AlexB
    Friday, November 21, 2008 9:27 PM
  • So as part of the application it shows the connecting computer's Timezone so how will that value be used to populate the database Timezone column?  The reason Timezone comes with Daylight savings time which may not be update based on the computer.  I know I lived in Indiana that changed to adjusted time but my computer which I bought in Indiana would not change the time. 


    Asp.net MVP, MCPD Web C#, MCTS TFS, MCITP BI and DBA
    Friday, November 21, 2008 9:44 PM
    Moderator
  • populate the various timezones in a dropdown

    This is what he said. He did not say that he wanted to have them accessible in a DB. He wants to see them in a dropdown. My interpretation of what he posted is that he wants to ogle them. His idea of getting there which is understandable since he has no idea of available options is to pull the info from somewhere, save it and then look at that. What I suggested is a workaround, provided my interpretation is correct. That GUI gives you Daylight Savings Time. : start and finish, and of course the Zone. It gives you neither time nor date.

    AlexB
    Saturday, November 22, 2008 3:55 AM
  • ( I want to save the timezone selected in database and display when ever the user revisits the application.)

    The above was from the first post of this thread.


    Asp.net MVP, MCPD Web C#, MCTS TFS, MCITP BI and DBA
    Saturday, November 22, 2008 4:33 AM
    Moderator
  •  But what if the DB is already available? A user can revisit and reuse the database that is already there. He does not need to build it.
    AlexB
    Saturday, November 22, 2008 1:30 PM
  • The ANSI SQL Time Interval arthemetic in SQL Server and Oracle takes values and do actual caculations of the users Time zone as the new .NET 3.5 Timezone structures David  and the other user posted. 

    You are talking about creating static Timezone values what all of us are talking about is generating timezone.  It has taken Microsoft almost twenty years to implement it in SQL Server it is not simple.


    Asp.net MVP, MCPD Web C#, MCTS TFS, MCITP BI and DBA
    Saturday, November 22, 2008 1:41 PM
    Moderator