Convert US Eastern Time to local .Net time?

Discussion in 'ASP .Net' started by Mark B, Sep 9, 2009.

  1. Mark B

    Mark B Guest

    We have a .Net VSTO Add-in for Outlook 2007.

    We receive a version DateTime field from our ASP.NET webservice from a
    server in Florida, e.g. dtServerDateTime in Eastern Time Zone DateTime.

    How can I convert this DateTime variable to the user's local computer time
    so I can display it on a form on their desktop? They may be in Brazil, the
    UK or another location.

    I am assuming our shared server hosted by serverintellect.com doesn't adjust
    for daylight savings too... If so I would need to take account of that and
    the local user's daylight saving I am guessing.
    Mark B, Sep 9, 2009
    #1
    1. Advertising

  2. Mark B schrieb:
    > We have a .Net VSTO Add-in for Outlook 2007.
    >
    > We receive a version DateTime field from our ASP.NET webservice from a
    > server in Florida, e.g. dtServerDateTime in Eastern Time Zone DateTime.
    >
    > How can I convert this DateTime variable to the user's local computer time
    > so I can display it on a form on their desktop? They may be in Brazil, the
    > UK or another location.




    Dim tziEastern = TimeZoneInfo.FindSystemTimeZoneById( _
    "Eastern Standard Time")
    Dim tziLocal = TimeZoneInfo.Local
    Dim EasternDateTime, LocalDateTime As DateTime

    EasternDateTime = #9/9/2009 11:00:00 PM#

    LocalDateTime = TimeZoneInfo.ConvertTime( _
    EasternDateTime, tziEastern, tziLocal)

    MsgBox(LocalDateTime)


    General hint: If you're dealing with different time zones, you may
    consider using the DateTimeOffset type instead of DateTime. In a global
    context, if the DateTime's 'Kind' property is 'local' it's not clear
    which locality is meant. (However, the ConvertTime function is clever
    enough to throw an exception if the DateTime object's Kind property
    value does not match the source time zone.) If you set the value by a
    DateTime literal, it's Kind=Unspecified.


    --
    Armin
    Armin Zingler, Sep 9, 2009
    #2
    1. Advertising

  3. Mark B

    Tom Shelton Guest

    On 2009-09-09, Mark B <> wrote:
    > We have a .Net VSTO Add-in for Outlook 2007.
    >
    > We receive a version DateTime field from our ASP.NET webservice from a
    > server in Florida, e.g. dtServerDateTime in Eastern Time Zone DateTime.
    >
    > How can I convert this DateTime variable to the user's local computer time
    > so I can display it on a form on their desktop? They may be in Brazil, the
    > UK or another location.
    >
    > I am assuming our shared server hosted by serverintellect.com doesn't adjust
    > for daylight savings too... If so I would need to take account of that and
    > the local user's daylight saving I am guessing.
    >


    If your using 3.5, then check out the TimeZoneInfo class. I believe it has
    methods to convert from one timezone to another...

    --
    Tom Shelton
    Tom Shelton, Sep 9, 2009
    #3
  4. Mark B

    Mark B Guest

    Thanks that worked but it was out by one hour:

    - The Florida server returned "9/09/2009 6:15:51 pm" (EDT at that time was
    actually 7:15:51 pm)
    - The VSTO app here in New Zealand returned "10/09/2009 10:15:51 am"

    However the time here in New Zealand was "11:15:51 am" not "10:15:51am".

    '-------
    Class DateTimeConvert

    Public Function fToLocal(ByVal dtRawDateTime As DateTime) As
    DateTime

    'To convert server time value to local time
    Dim tziEastern = TimeZoneInfo.FindSystemTimeZoneById("Eastern
    Standard Time")
    Dim tziLocal = TimeZoneInfo.Local
    Dim LocalDateTime As DateTime = Nothing
    LocalDateTime = TimeZoneInfo.ConvertTime(dtRawDateTime,
    tziEastern, tziLocal)
    Return LocalDateTime

    End Function

    End Class





    "Armin Zingler" <> wrote in message
    news:...
    > Mark B schrieb:
    >> We have a .Net VSTO Add-in for Outlook 2007.
    >>
    >> We receive a version DateTime field from our ASP.NET webservice from a
    >> server in Florida, e.g. dtServerDateTime in Eastern Time Zone DateTime.
    >>
    >> How can I convert this DateTime variable to the user's local computer
    >> time
    >> so I can display it on a form on their desktop? They may be in Brazil,
    >> the
    >> UK or another location.

    >
    >
    >
    > Dim tziEastern = TimeZoneInfo.FindSystemTimeZoneById( _
    > "Eastern Standard Time")
    > Dim tziLocal = TimeZoneInfo.Local
    > Dim EasternDateTime, LocalDateTime As DateTime
    >
    > EasternDateTime = #9/9/2009 11:00:00 PM#
    >
    > LocalDateTime = TimeZoneInfo.ConvertTime( _
    > EasternDateTime, tziEastern, tziLocal)
    >
    > MsgBox(LocalDateTime)
    >
    >
    > General hint: If you're dealing with different time zones, you may
    > consider using the DateTimeOffset type instead of DateTime. In a global
    > context, if the DateTime's 'Kind' property is 'local' it's not clear
    > which locality is meant. (However, the ConvertTime function is clever
    > enough to throw an exception if the DateTime object's Kind property
    > value does not match the source time zone.) If you set the value by a
    > DateTime literal, it's Kind=Unspecified.
    >
    >
    > --
    > Armin
    Mark B, Sep 10, 2009
    #4
    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. Matthias S.
    Replies:
    1
    Views:
    418
    OHM \( Terry Burns \)
    Mar 27, 2005
  2. John Smith
    Replies:
    1
    Views:
    319
    Earl Purple
    Aug 1, 2005
  3. Replies:
    1
    Views:
    776
    Paul Boddie
    Mar 11, 2007
  4. AaronLS

    South eastern tech cities

    AaronLS, Feb 2, 2009, in forum: Java
    Replies:
    10
    Views:
    615
  5. Jonathan Wood
    Replies:
    1
    Views:
    2,179
    Jonathan Wood
    Nov 1, 2009
Loading...

Share This Page