Converting the time from one timezone to another

Discussion in 'ASP .Net Building Controls' started by Nathan Sokalski, Feb 18, 2006.

  1. I asked a question about a week ago about how to get my local time, since my
    application is running on a server halfway around the world. I have
    determined that my code would look something like this:

    Dim servertime As Date = Date.Now

    Dim utctime As Date = servertime.ToUniversalTime()

    Dim localtime As Date


    I know that the last step would be to adjust the utctime value by the
    appropriate amount using code such as utctime.AddHours(-5), but I am looking
    for a way to get this value by supplying the timezone rather than an offset
    (in other words, I am looking for a function that returns either a
    System.TimeSpan or Integer when I enter the timezone) so that I can do
    something such as

    utctime.AddHours(GetTZOffset(TimeZones.EST))

    Is there a function that does this, or any way to get the offset by
    submitting the timezone? Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
    Nathan Sokalski, Feb 18, 2006
    #1
    1. Advertising

  2. William Stacey [MVP], Feb 18, 2006
    #2
    1. Advertising

  3. Nathan Sokalski

    aweska don Guest

    aweska don, Feb 18, 2006
    #3
  4. I could not find any code or links to download code on the page you gave a
    link to. Also, even though I will be using the code for SQL in some cases,
    my goal is to generate a System.DateTime object that is the local time. If I
    am missing the code, please let me know exactly where on your page it is.
    Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "William Stacey [MVP]" <> wrote in message
    news:...
    > See my UTC project for sql. It has the c# class you need.
    > http://channel9.msdn.com/ShowPost.aspx?PostID=142586
    >
    > --
    > William Stacey [MVP]
    > |
    >
    >
    Nathan Sokalski, Feb 18, 2006
    #4
  5. There is a "Save" link at the bottom of the article. Easy to miss. The
    APIs get and return DateTime, so you should be ok. Can use with sql or
    without. Let me know if you still have problems.

    --
    William Stacey [MVP]

    "Nathan Sokalski" <> wrote in message
    news:%23ji$...
    |I could not find any code or links to download code on the page you gave a
    | link to. Also, even though I will be using the code for SQL in some cases,
    | my goal is to generate a System.DateTime object that is the local time. If
    I
    | am missing the code, please let me know exactly where on your page it is.
    | Thanks.
    | --
    | Nathan Sokalski
    |
    | http://www.nathansokalski.com/
    |
    | "William Stacey [MVP]" <> wrote in message
    | news:...
    | > See my UTC project for sql. It has the c# class you need.
    | > http://channel9.msdn.com/ShowPost.aspx?PostID=142586
    | >
    | > --
    | > William Stacey [MVP]
    | > |
    | >
    | >
    |
    |
    William Stacey [MVP], Feb 18, 2006
    #5
  6. Nathan Sokalski

    Sandor Heese Guest

    have a look at this MSDN article:

    Coding Best Practices Using DateTime in the .NET Framework
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/datetimecode.asp

    it contains a lot of info about how to convert between timezones etc.

    Sandor

    "Nathan Sokalski" <> wrote in message
    news:...
    >I asked a question about a week ago about how to get my local time, since
    >my application is running on a server halfway around the world. I have
    >determined that my code would look something like this:
    >
    > Dim servertime As Date = Date.Now
    >
    > Dim utctime As Date = servertime.ToUniversalTime()
    >
    > Dim localtime As Date
    >
    >
    > I know that the last step would be to adjust the utctime value by the
    > appropriate amount using code such as utctime.AddHours(-5), but I am
    > looking for a way to get this value by supplying the timezone rather than
    > an offset (in other words, I am looking for a function that returns either
    > a System.TimeSpan or Integer when I enter the timezone) so that I can do
    > something such as
    >
    > utctime.AddHours(GetTZOffset(TimeZones.EST))
    >
    > Is there a function that does this, or any way to get the offset by
    > submitting the timezone? Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    Sandor Heese, Feb 23, 2006
    #6
  7. Nathan Sokalski

    clintonG Guest

    Thanks so much for posting that URL Sandor...

    <%= Clinton Gallagher

    "Sandor Heese" <> wrote in message
    news:%...
    > have a look at this MSDN article:
    >
    > Coding Best Practices Using DateTime in the .NET Framework
    > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/datetimecode.asp
    >
    > it contains a lot of info about how to convert between timezones etc.
    >
    > Sandor
    >
    > "Nathan Sokalski" <> wrote in message
    > news:...
    >>I asked a question about a week ago about how to get my local time, since
    >>my application is running on a server halfway around the world. I have
    >>determined that my code would look something like this:
    >>
    >> Dim servertime As Date = Date.Now
    >>
    >> Dim utctime As Date = servertime.ToUniversalTime()
    >>
    >> Dim localtime As Date
    >>
    >>
    >> I know that the last step would be to adjust the utctime value by the
    >> appropriate amount using code such as utctime.AddHours(-5), but I am
    >> looking for a way to get this value by supplying the timezone rather than
    >> an offset (in other words, I am looking for a function that returns
    >> either a System.TimeSpan or Integer when I enter the timezone) so that I
    >> can do something such as
    >>
    >> utctime.AddHours(GetTZOffset(TimeZones.EST))
    >>
    >> Is there a function that does this, or any way to get the offset by
    >> submitting the timezone? Thanks.
    >> --
    >> Nathan Sokalski
    >>
    >> http://www.nathansokalski.com/
    >>

    >
    >
    clintonG, Mar 2, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nathan Sokalski

    Converting the time from one timezone to another

    Nathan Sokalski, Feb 18, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    6,470
    clintonG
    Mar 2, 2006
  2. asaf
    Replies:
    3
    Views:
    6,144
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Sep 11, 2006
  3. kramesh
    Replies:
    1
    Views:
    555
    kramesh
    Apr 21, 2009
  4. Tharinda
    Replies:
    3
    Views:
    1,212
    peter koch
    Aug 25, 2010
  5. David Joseph Bonnici
    Replies:
    1
    Views:
    210
    Gunnar Hjalmarsson
    May 15, 2005
Loading...

Share This Page