Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Convert US Eastern Time to local .Net time?

Reply
Thread Tools

Convert US Eastern Time to local .Net time?

 
 
Mark B
Guest
Posts: n/a
 
      09-09-2009
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.

 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      09-09-2009
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
 
Reply With Quote
 
 
 
 
Tom Shelton
Guest
Posts: n/a
 
      09-09-2009
On 2009-09-09, Mark B <(E-Mail Removed)> 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
 
Reply With Quote
 
Mark B
Guest
Posts: n/a
 
      09-09-2009
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert UTC DateTime to Local Time (Not My Local Time) Jonathan Wood ASP .Net 1 11-01-2009 12:08 AM
convert UTC to local time(system time) and vice vesra in VB.NET deepak ASP .Net 1 02-06-2008 02:34 PM
convert time string in UTC to time in local time davelist@mac.com Python 1 03-11-2007 12:57 AM
convert local time to another country time Salim Afsar ASP .Net 2 03-16-2006 03:18 PM
Re: Is Trillian Messenger spyware? (First posted on 2003-07-16, at 3:35 am, Eastern Time) Martin Computer Support 0 07-20-2003 01:11 AM



Advertisments