Convert Local Time To Pacific Time

E

ECVerify.com

I am trying to convert a computers local time to Pacific time, I can
get it back to UTC pretty easy but I actually want to convert whatever
the local time is on the computer I want to calculate what it would
currently be in Pacific time. Taking in account Daylight Savings Time

Thanks, Ed,
 
E

ECVerify.com

Brian W said:
Have a look at the TimeZone class

HTH
Brian W

Brian, thanks but I have already looked there, but it seems that you
can only "Get" the current time zone...there is no way that I cna see
with that class to calculate a GMT time to a time in a time zone that
is not the local time of the computer it is on. But you can convert
the GMT tome with TimeZone to Local time, and that would work if the
users computers were in California, but they are not.


I did come up wit the following fuction but feel that Windows "should"
have a way to do it.

Public Shared Function UTCToPacificTime(ByVal UTC As DateTime)
As DateTime
Dim PacTime As DateTime
Dim StandardTime As Boolean = True

If (UTC.AddHours(-8).Month > 10 AndAlso
UTC.AddHours(-8).Month < 3) Then
StandardTime = False
End If

If ((UTC.AddHours(-8).DayOfWeek = DayOfWeek.Sunday)
AndAlso (UTC.AddHours(-8).Day > 24)) Then
If (UTC.AddHours(-8).Month = 10) AndAlso
(UTC.AddHours(-8).Hour > 2) Then
StandardTime = False
ElseIf (UTC.AddHours(-8).Month = 3) AndAlso
(UTC.AddHours(-8).Hour < 2) Then
StandardTime = False
End If
End If


If (StandardTime) Then
PacTime = UTC.AddHours(-8)
Else
PacTime = UTC.AddHours(-7)
End If

Return PacTime
End Function


Ed,
 
O

Ot

ECVerify.com said:
I did come up wit the following fuction but feel that Windows "should"
have a way to do it.

Ed,

I would suggest that you ask a different question. (I don't know that
answer either and would be interested.)

The "new" question:

Is there a way to manipulate the Local Time Zone that is settable by the
Control Panel : Date and Time Settings : Time Zone?

Can one detect and save the current setting?

If so... Then ...

Set CTZ = Current Time Zone
Set Current Time Zone to pacific (with automatic Daylight Savings
Detection)
Use elements of TimeZone class as needed
Reset CurrentTimeZone to CTZ.

Regards,
Ot


p.s. Your detection of IsDaylightTime in the code you provided needs
refinement. It is built in to the TimeZone class (for local time) and if
you run the app only in the US and not in AZ or HI (where there is not
daylight savings time) then you can use TimeZone's.
 
E

ECVerify.com

Ot said:
I would suggest that you ask a different question. (I don't know that
answer either and would be interested.)

The "new" question:

Is there a way to manipulate the Local Time Zone that is settable by the
Control Panel : Date and Time Settings : Time Zone?

Can one detect and save the current setting?

If so... Then ...

Set CTZ = Current Time Zone
Set Current Time Zone to pacific (with automatic Daylight Savings
Detection)
Use elements of TimeZone class as needed
Reset CurrentTimeZone to CTZ.

Regards,
Ot


p.s. Your detection of IsDaylightTime in the code you provided needs
refinement. It is built in to the TimeZone class (for local time) and if
you run the app only in the US and not in AZ or HI (where there is not
daylight savings time) then you can use TimeZone's.

Thanks for all the help, well I found a class with source and it is
phenomenal, in case others may want it here it is, it does all I
wanted and more.

http://www.michaelbrumm.com/simpletimezone.html

Once again thanks, Ed,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top