Converting the time from one timezone to another

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Converting the time from one timezone to another

    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
    [email]njsokalski@hotmail.com[/email]
    [url]http://www.nathansokalski.com/[/url]


    Nathan Sokalski Guest

  2. Similar Questions and Discussions

    1. #25825 [Opn->Asn]: Windows PHP always returns UTC time and BST as the timezone
      ID: 25825 Updated by: sniper@php.net Reported By: pennington at rhodes dot edu -Status: Open +Status: ...
    2. #25825 [Fbk->Opn]: Windows PHP always returns UTC time and BST as the timezone
      ID: 25825 User updated by: pennington at rhodes dot edu Reported By: pennington at rhodes dot edu -Status: Feedback...
    3. #25825 [Fbk->Bgs]: Windows PHP always returns UTC time and BST as the timezone
      ID: 25825 Updated by: sniper@php.net Reported By: pennington at rhodes dot edu -Status: Feedback +Status: ...
    4. #25592 [Opn->Bgs]: Get wrong timezone and time
      ID: 25592 Updated by: sniper@php.net Reported By: pennington at rhodes dot edu -Status: Open +Status: ...
    5. #25592 [NEW]: Get wrong timezone and time
      From: pennington at rhodes dot edu Operating system: Windows NT SP6a PHP version: 4.3.3 PHP Bug Type: Date/time related Bug...
  3. #2

    Default Re: Converting the time from one timezone to another

    See my UTC project for sql. It has the c# class you need.
    [url]http://channel9.msdn.com/ShowPost.aspx?PostID=142586[/url]

    --
    William Stacey [MVP]
    |


    William Stacey [MVP] Guest

  4. #3

    Default Re: Converting the time from one timezone to another

    Thanks

    [url]http://www.newbestweb.com[/url] owner

    aweska don Guest

  5. #4

    Default Re: Converting the time from one timezone to another

    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
    [email]njsokalski@hotmail.com[/email]
    [url]http://www.nathansokalski.com/[/url]

    "William Stacey [MVP]" <william.stacey@gmail.com> wrote in message
    news:epuJU1FNGHA.3276@TK2MSFTNGP09.phx.gbl...
    > See my UTC project for sql. It has the c# class you need.
    > [url]http://channel9.msdn.com/ShowPost.aspx?PostID=142586[/url]
    >
    > --
    > William Stacey [MVP]
    > |
    >
    >

    Nathan Sokalski Guest

  6. #5

    Default Re: Converting the time from one timezone to another

    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" <njsokalski@hotmail.com> wrote in message
    news:%23ji$GRLNGHA.916@TK2MSFTNGP10.phx.gbl...
    |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
    | [email]njsokalski@hotmail.com[/email]
    | [url]http://www.nathansokalski.com/[/url]
    |
    | "William Stacey [MVP]" <william.stacey@gmail.com> wrote in message
    | news:epuJU1FNGHA.3276@TK2MSFTNGP09.phx.gbl...
    | > See my UTC project for sql. It has the c# class you need.
    | > [url]http://channel9.msdn.com/ShowPost.aspx?PostID=142586[/url]
    | >
    | > --
    | > William Stacey [MVP]
    | > |
    | >
    | >
    |
    |


    William Stacey [MVP] Guest

  7. #6

    Default Re: Converting the time from one timezone to another

    have a look at this MSDN article:

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

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

    Sandor

    "Nathan Sokalski" <njsokalski@hotmail.com> wrote in message
    news:OZBJ1uFNGHA.2300@TK2MSFTNGP15.phx.gbl...
    >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
    > [email]njsokalski@hotmail.com[/email]
    > [url]http://www.nathansokalski.com/[/url]
    >

    Sandor Heese Guest

  8. #7

    Default Re: Converting the time from one timezone to another

    Thanks so much for posting that URL Sandor...

    <%= Clinton Gallagher

    "Sandor Heese" <nospam@nospam.com> wrote in message
    news:%23axbo7KOGHA.2268@TK2MSFTNGP09.phx.gbl...
    > have a look at this MSDN article:
    >
    > Coding Best Practices Using DateTime in the .NET Framework
    > [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/datetimecode.asp[/url]
    >
    > it contains a lot of info about how to convert between timezones etc.
    >
    > Sandor
    >
    > "Nathan Sokalski" <njsokalski@hotmail.com> wrote in message
    > news:OZBJ1uFNGHA.2300@TK2MSFTNGP15.phx.gbl...
    >>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
    >> [email]njsokalski@hotmail.com[/email]
    >> [url]http://www.nathansokalski.com/[/url]
    >>
    >
    >

    clintonG Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139