convert UTC to EST

sdlangers

Well-known member
Joined
Dec 3, 2002
Messages
118
Hi All,

What is the easiest way to convert a date that is in UTC to EST using vb.net?

I dont want to simply subtract 5 hours, cos this wont work during daylight savings times.

Are there any fucntions to do this?

thanks.
 
It depends. If the code is running on a machine that has its timezone set to Eastern Standard Time the answer is rather simple, and you need only to call the [msdn]System.TimeZone[/msdn].ToLocalTime() method. If this is not the case, then you will have to perform the conversion manually.
 
hi derek,

thanks, but there is no system.timezone.toLocalTime that i can see

if there was such a function that would work, it wouldnt matter which zone i was in, as long as its standard - e.g. the server is always in PST, so we could use the toLocalTime function and then just add 3, since PST and EST are always in the same daylight savings times.

any ideas why i dont get a ToLocalTime() method?

thanks
 
ok - i found it.. here it is incase anyone else wants it:

Code:
Dim tz As TimeZone = System.TimeZone.CurrentTimeZone
Dim intHoursDifference As Integer
Dim testUTC As DateTime = Now.UtcNow

 check if were in Daylight Savings Time now
If tz.IsDaylightSavingTime(Now) Then
     EST is 4 hours difference
    intHoursDifference = -4
Else
     EST is 5 hours difference
    intHoursDifference = -5
End If

MsgBox("UTC Time in EST is " & DateAdd(DateInterval.Hour, intHoursDifference, testUTC))
 
Last edited by a moderator:
Back
Top