You can use DateTime.GetTimeZoneOffsetAt to get the timezone at any given time.
In most cases when a developer calls the time zone related methods then it is a sign that he is doing something wrong.
Sub IsDaylightInEffect As Boolean
Dim currentTimezone As Double = DateTime.TimeZoneOffset
Dim t As Long = DateTime.Now
For i = 0 To 11 Step 2
If DateTime.GetTimeZoneOffsetAt(t) < currentTimezone Then Return True
t = t + i * DateTime.TicksPerDay * 30
Next
Return False
End Sub
My issue is: I want to display the time of sunrise at the users location. I calculate the sunrise time based on GMT. Using the code above, I know if daylight savings is active or not, and add an hour if necessary (DST).
But what if I want to calculate the time of sunrise on some arbitrary date (at the users location). For example, how do I know if DST is active on the 1st March?
Sub Process_Globals
Private MinTimeZone As Double
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
FindMinTimeZone
End If
Log(IsDST(DateTime.Now))
Log(IsDST(DateTime.DateParse("08/01/2000")))
End Sub
Private Sub FindMinTimeZone
Dim t As Long = DateTime.Now
MinTimeZone = DateTime.GetTimeZoneOffsetAt(t)
For i = 1 To 400
Dim m As Double = DateTime.GetTimeZoneOffsetAt(t)
If m <> MinTimeZone Then
MinTimeZone = Min(m, MinTimeZone)
Exit
End If
t = t + DateTime.TicksPerDay
Next
End Sub
Public Sub IsDST(t As Long) As Boolean
Return DateTime.GetTimeZoneOffsetAt(t) > MinTimeZone
End Sub
Another solution is this library that does everything for you. You just need to enter your current location via GPS location or FusedLocationProvider, enter the time, and read your gettimezoneoffset from you phone and you are sorted no matter where you are located in the world. Enter one one into the library and it gives you all the results that you need.
I've updated my last post, you should read it again
Yes I've been using that library for years with weather apps that I've created. The library is really easy to use, you will have your app up and running perfect within 10 minutes with basically a hand full of your own lines of code