C
Chad
I'm looking for the best way to convert a date/time to UTC and back to
Local.
This has to be built in the Framework, but eberything I try gives me
something other than what I expect!
I was tempted to do get the current offset from GMT and use that IN ALL
CASES to convert to and fro, but this offset isn't always the same across
seasons, due to daylights savings, etc.
Here's my sorry excuse for TZ conversion functions. Can someone give me a
better way?
Public Shared Function LocalToUtc(ByVal localTime As Date) As Date
Return DateAdd(DateInterval.Minute, MinuteOffsetFromUtc, localTime)
End Function
Public Shared Function UtlToLocal(ByVal localTime As Date) As Date
Return DateAdd(DateInterval.Minute, -MinuteOffsetFromUtc(), localTime)
End Function
Public Shared Function MinuteOffsetFromUtc() As Long
Static BeenHere As Boolean
Static Offset As Long = Nothing
If Not BeenHere Then
Offset = DateDiff(DateInterval.Minute, My.Computer.Clock.GmtTime,
My.Computer.Clock.LocalTime)
BeenHere = True
End If
Return Offset
End Function
Local.
This has to be built in the Framework, but eberything I try gives me
something other than what I expect!
I was tempted to do get the current offset from GMT and use that IN ALL
CASES to convert to and fro, but this offset isn't always the same across
seasons, due to daylights savings, etc.
Here's my sorry excuse for TZ conversion functions. Can someone give me a
better way?
Public Shared Function LocalToUtc(ByVal localTime As Date) As Date
Return DateAdd(DateInterval.Minute, MinuteOffsetFromUtc, localTime)
End Function
Public Shared Function UtlToLocal(ByVal localTime As Date) As Date
Return DateAdd(DateInterval.Minute, -MinuteOffsetFromUtc(), localTime)
End Function
Public Shared Function MinuteOffsetFromUtc() As Long
Static BeenHere As Boolean
Static Offset As Long = Nothing
If Not BeenHere Then
Offset = DateDiff(DateInterval.Minute, My.Computer.Clock.GmtTime,
My.Computer.Clock.LocalTime)
BeenHere = True
End If
Return Offset
End Function