TimeZones

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael

    #1

    TimeZones

    I would like to set the timezone of a thread to allow me
    to calculate the UTC time for data sourced from a number
    of time zones. Although this can be done in C and C++, I
    annot find how to do this is C#. Can this be done ? If
    so how ?

    Please note setting the culture does not impact the
    timezone and a culture (like en-US) may have many
    timezones.
  • Felix Wang

    #2
    RE: TimeZones

    Hi Michael,

    Thanks for posting.

    Could you elaborate a little bit more on "data sourced from a number of
    time zones"? Is it string data or the timestamps on the file?

    In .Net, we have a structure "System.DateTim e". It contains some members
    ("Parse", "ToUniversalTim e", "FromFileTimeUt c" etc.) that may be helpful to
    you:

    http://msdn.microsoft.com/library/de...us/cpref/html/
    frlrfSystemDate TimeMembersTopi c.asp?frame=tru e

    In addition, there is also a class named "System.TimeZon e":

    http://msdn.microsoft.com/library/de...us/cpref/html/
    frlrfSystemTime ZoneClassTopic. asp?frame=true

    Please check and see whether or not these help to achieve your goal.

    Happy Thanksgiving!

    Regards,

    Felix Wang
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.

    Comment

    • Bruno Jouhier [MVP]

      #3
      Re: TimeZones

      You cannot do this with the current framework, and the TimeZone API is
      really poor. You cannot enumerate available timezones, you cannot even
      create a timezone with a given offset. All you can do is read the machine's
      timezone, as it has been configured through the control panel, and convert
      DateTime to UTC and back to the local timezone.

      This is really insufficient. I have posted a request to enhance the timezone
      API on the Whidbey beta newsgroup, asking specifically for the following
      features:

      * Enumerating timezones

      * Associating a timezone to the current thread, the same way you can
      associate a culture to the current thread, which is exactly what you suggest
      (of course you can define your own ThreadStatic variable, but it won't have
      any influence on the way DateTimes are formatted and parsed, so it is of
      very little help, we need a framework level variable that works like
      CultureInfo.Cur rentCulture).

      I would really like to see this feature in the next version of the
      framework, but I feel that it won't make it unless more people complain
      about the weakness of the current API (usually the .NET API is richer than
      the Java API, but here is is much weaker). So, if you feel that the TimeZone
      API is too weak, and if you want this feature in the next version of the
      Framework, raise your voice.

      Bruno.

      "Michael" <michaelro@avan ade.com> a écrit dans le message de
      news:7cb101c3b4 8b$d90fc8d0$a60 1280a@phx.gbl.. .[color=blue]
      > I would like to set the timezone of a thread to allow me
      > to calculate the UTC time for data sourced from a number
      > of time zones. Although this can be done in C and C++, I
      > annot find how to do this is C#. Can this be done ? If
      > so how ?
      >
      > Please note setting the culture does not impact the
      > timezone and a culture (like en-US) may have many
      > timezones.[/color]


      Comment

      • Ron McNulty

        #4
        Re: TimeZones

        Hi Michael

        Although not possible with the current API, there are several solutions for
        Windows operating systems available. They all rely on the registry info for
        timezones. Google on '.NET C# Timezone'.

        Regards

        Ron

        "Michael" <michaelro@avan ade.com> wrote in message
        news:7cb101c3b4 8b$d90fc8d0$a60 1280a@phx.gbl.. .[color=blue]
        > I would like to set the timezone of a thread to allow me
        > to calculate the UTC time for data sourced from a number
        > of time zones. Although this can be done in C and C++, I
        > annot find how to do this is C#. Can this be done ? If
        > so how ?
        >
        > Please note setting the culture does not impact the
        > timezone and a culture (like en-US) may have many
        > timezones.[/color]


        Comment

        • Ron McNulty

          #5
          Re: TimeZones

          Come on Felix, why not just reply that .NET timezone support is rudimentary?
          Bruno has summarised its failings.

          Regards

          Ron

          "Felix Wang" <v-felwa@online.mi crosoft.com> wrote in message
          news:qpSZ4hLtDH A.636@cpmsftngx a06.phx.gbl...[color=blue]
          > Hi Michael,
          >
          > Thanks for posting.
          >
          > Could you elaborate a little bit more on "data sourced from a number of
          > time zones"? Is it string data or the timestamps on the file?
          >
          > In .Net, we have a structure "System.DateTim e". It contains some members
          > ("Parse", "ToUniversalTim e", "FromFileTimeUt c" etc.) that may be helpful[/color]
          to[color=blue]
          > you:
          >
          >[/color]
          http://msdn.microsoft.com/library/de...us/cpref/html/[color=blue]
          > frlrfSystemDate TimeMembersTopi c.asp?frame=tru e
          >
          > In addition, there is also a class named "System.TimeZon e":
          >
          >[/color]
          http://msdn.microsoft.com/library/de...us/cpref/html/[color=blue]
          > frlrfSystemTime ZoneClassTopic. asp?frame=true
          >
          > Please check and see whether or not these help to achieve your goal.
          >
          > Happy Thanksgiving!
          >
          > Regards,
          >
          > Felix Wang
          > Microsoft Online Partner Support
          > Get Secure! - www.microsoft.com/security
          > This posting is provided "as is" with no warranties and confers no rights.
          >[/color]


          Comment

          • Ron Vecchi

            #6
            Re: TimeZones

            Hello Bruno,

            Although off topic where can I find the Whidbey Beta Group you referenced.
            What is Whidbey?

            I would very much like to see timezone handling in .Net also and have spent
            a couple long nights tring to handle a users current time based on zone.
            Specifically I was playing around with a web app that implemented satelite
            assemblies with localization. The website adjusted the assembly bases on
            the browser (default) or user specified setting of their culture. But when
            I wanted to handle time with the users I ran into a huge mess tring to
            figure it out. Especially when getting into daylight savings and other
            details.

            Where can I go to post this request along with yours? It would make things
            much easier.


            "Bruno Jouhier [MVP]" <bjouhier@clu b-internet.fr> wrote in message
            news:OLUpImLtDH A.2520@TK2MSFTN GP10.phx.gbl...[color=blue]
            > You cannot do this with the current framework, and the TimeZone API is
            > really poor. You cannot enumerate available timezones, you cannot even
            > create a timezone with a given offset. All you can do is read the[/color]
            machine's[color=blue]
            > timezone, as it has been configured through the control panel, and convert
            > DateTime to UTC and back to the local timezone.
            >
            > This is really insufficient. I have posted a request to enhance the[/color]
            timezone[color=blue]
            > API on the Whidbey beta newsgroup, asking specifically for the following
            > features:
            >
            > * Enumerating timezones
            >
            > * Associating a timezone to the current thread, the same way you can
            > associate a culture to the current thread, which is exactly what you[/color]
            suggest[color=blue]
            > (of course you can define your own ThreadStatic variable, but it won't[/color]
            have[color=blue]
            > any influence on the way DateTimes are formatted and parsed, so it is of
            > very little help, we need a framework level variable that works like
            > CultureInfo.Cur rentCulture).
            >
            > I would really like to see this feature in the next version of the
            > framework, but I feel that it won't make it unless more people complain
            > about the weakness of the current API (usually the .NET API is richer than
            > the Java API, but here is is much weaker). So, if you feel that the[/color]
            TimeZone[color=blue]
            > API is too weak, and if you want this feature in the next version of the
            > Framework, raise your voice.
            >
            > Bruno.
            >
            > "Michael" <michaelro@avan ade.com> a écrit dans le message de
            > news:7cb101c3b4 8b$d90fc8d0$a60 1280a@phx.gbl.. .[color=green]
            > > I would like to set the timezone of a thread to allow me
            > > to calculate the UTC time for data sourced from a number
            > > of time zones. Although this can be done in C and C++, I
            > > annot find how to do this is C#. Can this be done ? If
            > > so how ?
            > >
            > > Please note setting the culture does not impact the
            > > timezone and a culture (like en-US) may have many
            > > timezones.[/color]
            >
            >[/color]


            Comment

            • Michael

              #7
              Re: TimeZones

              Felix,

              The system "merges" data from a number of servers. The
              servers are in different timezones. The data includes
              datetime fields with the datetime in local format and not
              stored as UTC time.


              So the cultural differences can be handled be setting
              "Thread.Current Thread.CurrentC ulture".

              There is no timezone equivalent (I think we need
              "Thread.Current Thread.CurrentT imezone".

              I can't really on a fixed offset as then daylight saving
              light is not handled. The fix looks like writing a little
              app to run on the soruce system and return the culture and
              offset.

              C and C++ offer tx handling and setting, C# should as well.

              Michael.[color=blue]
              >-----Original Message-----
              >Come on Felix, why not just reply that .NET timezone[/color]
              support is rudimentary?[color=blue]
              >Bruno has summarised its failings.
              >
              >Regards
              >
              >Ron
              >
              >"Felix Wang" <v-felwa@online.mi crosoft.com> wrote in[/color]
              message[color=blue]
              >news:qpSZ4hLtD HA.636@cpmsftng xa06.phx.gbl...[color=green]
              >> Hi Michael,
              >>
              >> Thanks for posting.
              >>
              >> Could you elaborate a little bit more on "data sourced[/color][/color]
              from a number of[color=blue][color=green]
              >> time zones"? Is it string data or the timestamps on the[/color][/color]
              file?[color=blue][color=green]
              >>
              >> In .Net, we have a structure "System.DateTim e". It[/color][/color]
              contains some members[color=blue][color=green]
              >> ("Parse", "ToUniversalTim e", "FromFileTimeUt c" etc.)[/color][/color]
              that may be helpful[color=blue]
              >to[color=green]
              >> you:
              >>
              >>[/color]
              >http://msdn.microsoft.com/library/default.asp?[/color]
              url=/library/en-us/cpref/html/[color=blue][color=green]
              >> frlrfSystemDate TimeMembersTopi c.asp?frame=tru e
              >>
              >> In addition, there is also a class[/color][/color]
              named "System.TimeZon e":[color=blue][color=green]
              >>
              >>[/color]
              >http://msdn.microsoft.com/library/default.asp?[/color]
              url=/library/en-us/cpref/html/[color=blue][color=green]
              >> frlrfSystemTime ZoneClassTopic. asp?frame=true
              >>
              >> Please check and see whether or not these help to[/color][/color]
              achieve your goal.[color=blue][color=green]
              >>
              >> Happy Thanksgiving!
              >>
              >> Regards,
              >>
              >> Felix Wang
              >> Microsoft Online Partner Support
              >> Get Secure! - www.microsoft.com/security
              >> This posting is provided "as is" with no warranties and[/color][/color]
              confers no rights.[color=blue][color=green]
              >>[/color]
              >
              >
              >.
              >[/color]

              Comment

              • Bruno Jouhier [MVP]

                #8
                Re: TimeZones

                Hello Ron,

                Whidbey is the code name for the next version of Visual Studio .NET. I'm
                lucky enough to be enrolled in their beta program. The newsgroups are
                private newsgroups reserved to beta testers. You should contact Microsoft if
                you want to participate to the beta program.

                Our web application has requirements similar to yours. We would like every
                visitor to feel completely "at home", i.e. get a fully localized site with
                messages in his language, and times formatted in his timezone. As the server
                is multi-threaded, we need the ability to set a different TimeZone in every
                thread.

                I will repost on the Whidbey newsgroup, with a reference to this thread, to
                try to catch the attention of the people who control what will go into the
                next iteration of the framework.

                Today, we use a workaround: we use the Java API to manipulate timezones. You
                don't even need to program in J# to do it, you can do it in C# by adding a
                reference to vjslib in your C# project. Then, you can use the Java TimeZone
                class from the java.util namespace (note: it is buggy on NT4). This
                workaround gives us access to a richer TimeZone API but is not fully
                satisfactory because DateTime values are still formatted with the machine's
                timezone, we have no way to set a thread-level variable that would influence
                this.

                Bruno.


                "Ron Vecchi" <rvecchi@xilehd vecchi.com> a écrit dans le message de
                news:%23lC%23J4 PtDHA.2520@TK2M SFTNGP10.phx.gb l...[color=blue]
                > Hello Bruno,
                >
                > Although off topic where can I find the Whidbey Beta Group you referenced.
                > What is Whidbey?
                >
                > I would very much like to see timezone handling in .Net also and have[/color]
                spent[color=blue]
                > a couple long nights tring to handle a users current time based on zone.
                > Specifically I was playing around with a web app that implemented satelite
                > assemblies with localization. The website adjusted the assembly bases on
                > the browser (default) or user specified setting of their culture. But[/color]
                when[color=blue]
                > I wanted to handle time with the users I ran into a huge mess tring to
                > figure it out. Especially when getting into daylight savings and other
                > details.
                >
                > Where can I go to post this request along with yours? It would make[/color]
                things[color=blue]
                > much easier.
                >
                >
                > "Bruno Jouhier [MVP]" <bjouhier@clu b-internet.fr> wrote in message
                > news:OLUpImLtDH A.2520@TK2MSFTN GP10.phx.gbl...[color=green]
                > > You cannot do this with the current framework, and the TimeZone API is
                > > really poor. You cannot enumerate available timezones, you cannot even
                > > create a timezone with a given offset. All you can do is read the[/color]
                > machine's[color=green]
                > > timezone, as it has been configured through the control panel, and[/color][/color]
                convert[color=blue][color=green]
                > > DateTime to UTC and back to the local timezone.
                > >
                > > This is really insufficient. I have posted a request to enhance the[/color]
                > timezone[color=green]
                > > API on the Whidbey beta newsgroup, asking specifically for the following
                > > features:
                > >
                > > * Enumerating timezones
                > >
                > > * Associating a timezone to the current thread, the same way you can
                > > associate a culture to the current thread, which is exactly what you[/color]
                > suggest[color=green]
                > > (of course you can define your own ThreadStatic variable, but it won't[/color]
                > have[color=green]
                > > any influence on the way DateTimes are formatted and parsed, so it is of
                > > very little help, we need a framework level variable that works like
                > > CultureInfo.Cur rentCulture).
                > >
                > > I would really like to see this feature in the next version of the
                > > framework, but I feel that it won't make it unless more people complain
                > > about the weakness of the current API (usually the .NET API is richer[/color][/color]
                than[color=blue][color=green]
                > > the Java API, but here is is much weaker). So, if you feel that the[/color]
                > TimeZone[color=green]
                > > API is too weak, and if you want this feature in the next version of the
                > > Framework, raise your voice.
                > >
                > > Bruno.
                > >
                > > "Michael" <michaelro@avan ade.com> a écrit dans le message de
                > > news:7cb101c3b4 8b$d90fc8d0$a60 1280a@phx.gbl.. .[color=darkred]
                > > > I would like to set the timezone of a thread to allow me
                > > > to calculate the UTC time for data sourced from a number
                > > > of time zones. Although this can be done in C and C++, I
                > > > annot find how to do this is C#. Can this be done ? If
                > > > so how ?
                > > >
                > > > Please note setting the culture does not impact the
                > > > timezone and a culture (like en-US) may have many
                > > > timezones.[/color]
                > >
                > >[/color]
                >
                >[/color]


                Comment

                • Bruno Jouhier [MVP]

                  #9
                  Re: TimeZones

                  Hi Ron,

                  Another way is to use the java.util.TimeZ one class from the J# runtime, as I
                  mention in another response.

                  Bruno.
                  "Ron McNulty" <rmcnulty@despa m.xtra.co.nz> a écrit dans le message de
                  news:e3lUvNMtDH A.3744@TK2MSFTN GP11.phx.gbl...[color=blue]
                  > Hi Michael
                  >
                  > Although not possible with the current API, there are several solutions[/color]
                  for[color=blue]
                  > Windows operating systems available. They all rely on the registry info[/color]
                  for[color=blue]
                  > timezones. Google on '.NET C# Timezone'.
                  >
                  > Regards
                  >
                  > Ron
                  >
                  > "Michael" <michaelro@avan ade.com> wrote in message
                  > news:7cb101c3b4 8b$d90fc8d0$a60 1280a@phx.gbl.. .[color=green]
                  > > I would like to set the timezone of a thread to allow me
                  > > to calculate the UTC time for data sourced from a number
                  > > of time zones. Although this can be done in C and C++, I
                  > > annot find how to do this is C#. Can this be done ? If
                  > > so how ?
                  > >
                  > > Please note setting the culture does not impact the
                  > > timezone and a culture (like en-US) may have many
                  > > timezones.[/color]
                  >
                  >[/color]


                  Comment

                  • Bruno Jouhier [MVP]

                    #10
                    Re: TimeZones

                    > There is no timezone equivalent (I think we need[color=blue]
                    > "Thread.Current Thread.CurrentT imezone".[/color]

                    Yes, this is what we really need.

                    Bruno.


                    Comment

                    • Bruno Jouhier [MVP]

                      #11
                      Re: TimeZones

                      Hi Ron,
                      "Ron McNulty" <rmcnulty@despa m.xtra.co.nz> a écrit dans le message de
                      news:e3lUvNMtDH A.3744@TK2MSFTN GP11.phx.gbl...[color=blue]
                      > Hi Michael
                      >
                      > Although not possible with the current API, there are several solutions[/color]
                      for[color=blue]
                      > Windows operating systems available. They all rely on the registry info[/color]
                      for[color=blue]
                      > timezones. Google on '.NET C# Timezone'.
                      >
                      > Regards
                      >
                      > Ron
                      >
                      > "Michael" <michaelro@avan ade.com> wrote in message
                      > news:7cb101c3b4 8b$d90fc8d0$a60 1280a@phx.gbl.. .[color=green]
                      > > I would like to set the timezone of a thread to allow me
                      > > to calculate the UTC time for data sourced from a number
                      > > of time zones. Although this can be done in C and C++, I
                      > > annot find how to do this is C#. Can this be done ? If
                      > > so how ?
                      > >
                      > > Please note setting the culture does not impact the
                      > > timezone and a culture (like en-US) may have many
                      > > timezones.[/color]
                      >
                      >[/color]


                      Comment

                      • Felix Wang

                        #12
                        Re: TimeZones

                        Hi Michael,

                        I have to admit that the time zone support in the current .Net Framework is
                        not sufficient. It is very complicated to calculate daylight saving
                        time/periods among different areas and the rules are subject to changes.

                        I think the most convenient way to solve this may be to collect the UTC
                        time instead of local time from the servers.

                        Happy Thanksgiving!

                        Regards,

                        Felix Wang
                        Microsoft Online Partner Support
                        Get Secure! - www.microsoft.com/security
                        This posting is provided "as is" with no warranties and confers no rights.

                        Comment

                        • Ron Vecchi

                          #13
                          Re: TimeZones

                          Thanks Bruno,

                          Iam just getting ready to investigate the Java work around

                          "Bruno Jouhier [MVP]" <bjouhier@clu b-internet.fr> wrote in message
                          news:#AmnmUYtDH A.556@TK2MSFTNG P11.phx.gbl...[color=blue]
                          > Hello Ron,
                          >
                          > Whidbey is the code name for the next version of Visual Studio .NET. I'm
                          > lucky enough to be enrolled in their beta program. The newsgroups are
                          > private newsgroups reserved to beta testers. You should contact Microsoft[/color]
                          if[color=blue]
                          > you want to participate to the beta program.
                          >
                          > Our web application has requirements similar to yours. We would like every
                          > visitor to feel completely "at home", i.e. get a fully localized site with
                          > messages in his language, and times formatted in his timezone. As the[/color]
                          server[color=blue]
                          > is multi-threaded, we need the ability to set a different TimeZone in[/color]
                          every[color=blue]
                          > thread.
                          >
                          > I will repost on the Whidbey newsgroup, with a reference to this thread,[/color]
                          to[color=blue]
                          > try to catch the attention of the people who control what will go into the
                          > next iteration of the framework.
                          >
                          > Today, we use a workaround: we use the Java API to manipulate timezones.[/color]
                          You[color=blue]
                          > don't even need to program in J# to do it, you can do it in C# by adding a
                          > reference to vjslib in your C# project. Then, you can use the Java[/color]
                          TimeZone[color=blue]
                          > class from the java.util namespace (note: it is buggy on NT4). This
                          > workaround gives us access to a richer TimeZone API but is not fully
                          > satisfactory because DateTime values are still formatted with the[/color]
                          machine's[color=blue]
                          > timezone, we have no way to set a thread-level variable that would[/color]
                          influence[color=blue]
                          > this.
                          >
                          > Bruno.
                          >
                          >
                          > "Ron Vecchi" <rvecchi@xilehd vecchi.com> a écrit dans le message de
                          > news:%23lC%23J4 PtDHA.2520@TK2M SFTNGP10.phx.gb l...[color=green]
                          > > Hello Bruno,
                          > >
                          > > Although off topic where can I find the Whidbey Beta Group you[/color][/color]
                          referenced.[color=blue][color=green]
                          > > What is Whidbey?
                          > >
                          > > I would very much like to see timezone handling in .Net also and have[/color]
                          > spent[color=green]
                          > > a couple long nights tring to handle a users current time based on zone.
                          > > Specifically I was playing around with a web app that implemented[/color][/color]
                          satelite[color=blue][color=green]
                          > > assemblies with localization. The website adjusted the assembly bases[/color][/color]
                          on[color=blue][color=green]
                          > > the browser (default) or user specified setting of their culture. But[/color]
                          > when[color=green]
                          > > I wanted to handle time with the users I ran into a huge mess tring to
                          > > figure it out. Especially when getting into daylight savings and other
                          > > details.
                          > >
                          > > Where can I go to post this request along with yours? It would make[/color]
                          > things[color=green]
                          > > much easier.
                          > >
                          > >
                          > > "Bruno Jouhier [MVP]" <bjouhier@clu b-internet.fr> wrote in message
                          > > news:OLUpImLtDH A.2520@TK2MSFTN GP10.phx.gbl...[color=darkred]
                          > > > You cannot do this with the current framework, and the TimeZone API is
                          > > > really poor. You cannot enumerate available timezones, you cannot even
                          > > > create a timezone with a given offset. All you can do is read the[/color]
                          > > machine's[color=darkred]
                          > > > timezone, as it has been configured through the control panel, and[/color][/color]
                          > convert[color=green][color=darkred]
                          > > > DateTime to UTC and back to the local timezone.
                          > > >
                          > > > This is really insufficient. I have posted a request to enhance the[/color]
                          > > timezone[color=darkred]
                          > > > API on the Whidbey beta newsgroup, asking specifically for the[/color][/color][/color]
                          following[color=blue][color=green][color=darkred]
                          > > > features:
                          > > >
                          > > > * Enumerating timezones
                          > > >
                          > > > * Associating a timezone to the current thread, the same way you can
                          > > > associate a culture to the current thread, which is exactly what you[/color]
                          > > suggest[color=darkred]
                          > > > (of course you can define your own ThreadStatic variable, but it won't[/color]
                          > > have[color=darkred]
                          > > > any influence on the way DateTimes are formatted and parsed, so it is[/color][/color][/color]
                          of[color=blue][color=green][color=darkred]
                          > > > very little help, we need a framework level variable that works like
                          > > > CultureInfo.Cur rentCulture).
                          > > >
                          > > > I would really like to see this feature in the next version of the
                          > > > framework, but I feel that it won't make it unless more people[/color][/color][/color]
                          complain[color=blue][color=green][color=darkred]
                          > > > about the weakness of the current API (usually the .NET API is richer[/color][/color]
                          > than[color=green][color=darkred]
                          > > > the Java API, but here is is much weaker). So, if you feel that the[/color]
                          > > TimeZone[color=darkred]
                          > > > API is too weak, and if you want this feature in the next version of[/color][/color][/color]
                          the[color=blue][color=green][color=darkred]
                          > > > Framework, raise your voice.
                          > > >
                          > > > Bruno.
                          > > >
                          > > > "Michael" <michaelro@avan ade.com> a écrit dans le message de
                          > > > news:7cb101c3b4 8b$d90fc8d0$a60 1280a@phx.gbl.. .
                          > > > > I would like to set the timezone of a thread to allow me
                          > > > > to calculate the UTC time for data sourced from a number
                          > > > > of time zones. Although this can be done in C and C++, I
                          > > > > annot find how to do this is C#. Can this be done ? If
                          > > > > so how ?
                          > > > >
                          > > > > Please note setting the culture does not impact the
                          > > > > timezone and a culture (like en-US) may have many
                          > > > > timezones.
                          > > >
                          > > >[/color]
                          > >
                          > >[/color]
                          >
                          >[/color]


                          Comment

                          • Michael Sundermann

                            #14
                            Re: TimeZones


                            I have written a component which supports time zone
                            and daylight saving time in .NET.
                            maybe this hint will helps you.

                            michael




                            Comment

                            Working...