PC Review


Reply
Thread Tools Rate Thread

Convert US Eastern Time to local .Net time?

 
 
Mark B
Guest
Posts: n/a
 
      9th Sep 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
 
      9th Sep 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
 
      9th Sep 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
 
      10th Sep 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
Rate This Thread
Rate This Thread:

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 US Eastern Time to local .Net time? Mark B Microsoft VB .NET 3 10th Sep 2009 12:33 AM
Convert US Eastern Time to local .Net C# time? Mark B Microsoft C# .NET 1 9th Sep 2009 02:46 PM
Is there a way to auto convert a time stamps to Eastern Standard T DR Microsoft Excel Programming 13 2nd Aug 2008 01:29 AM
In Excel, I want to convert Eastern time to pacific time =?Utf-8?B?ZG11bmhhbGw=?= Microsoft Excel Misc 4 1st Apr 2006 01:03 AM
How do you convert Eastern Time zone to GMT datetime GG Microsoft C# .NET 1 7th Jul 2005 09:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:22 AM.