Android Question Need to know what time it is EST with DST accounted for

BumForALiving

Member
Licensed User
Longtime User
No matter where my app is run in the world, I need to know what time it is EST.

When setting the time zone to EST using DateTime.SetTimeZone(-5) the time is off by an hour which must be related to daylight savings time.

How do I properly detect EST accounting for DST?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
No. This will set the time zone to -4.

You can use this code:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   SetTimeZone("America/New_York")
   Log(DateTime.Time(DateTime.Now))
End Sub

Sub SetTimeZone(id As String)
   Dim r As Reflector
   Dim idTz As Object = r.RunStaticMethod("java.util.TimeZone", "getTimeZone", Array As String(id), _
     Array As String("java.lang.String"))
   r.RunStaticMethod("anywheresoftware.b4a.keywords.DateTime", "setTimeZoneInternal", _
     Array As Object(idTz), Array As String("java.util.TimeZone"))
End Sub
 
Upvote 0
Top