B4J Question DateTime.Now value

hanyelmehy

Active Member
Licensed User
Longtime User
DateTime.Now return time not match with PC time (-1h)
i need simple way to get same PC time ,without any addtional setting
 

Daestrum

Expert
Licensed User
Longtime User
Sounds like a daylight saving setting problem. Are you sure DST is on? (assuming you are in a country that has daylight saving)
 
Upvote 0

hanyelmehy

Active Member
Licensed User
Longtime User
yes we have daylight saving and setting DateTime.SetTimeZone to +1 solve the issue but these make user need to adjust time by him self
i just want to simpley get exact PC time like its without needing for any addtional adjustment
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
I don't see that problem on my pc the time returned from
B4X:
DateTime.Time(DateTime.Now)
is the same as the pc clock.
 
Upvote 0

hanyelmehy

Active Member
Licensed User
Longtime User
I don't see that problem on my pc the time returned from
B4X:
DateTime.Time(DateTime.Now)
is the same as the pc clock.
in my case
B4X:
DateTime.Time(DateTime.Now)
return PC Time -1h , i need to adjust DateTime.SetTimeZone to +1
 
Upvote 0

hanyelmehy

Active Member
Licensed User
Longtime User
What is your PC timezone?
What is the output of:
B4X:
Log("offset: " & DateTime.TimeZoneOffset)
Log(DateTime.Now)
Log(DateTime.Time(DateTime.Now))
Time Zone :UTC+02.00
Note :we have now daylight saving
B4X:
offset: 0
1725265773364
08:29 AM
 
Upvote 0

hanyelmehy

Active Member
Licensed User
Longtime User
What is the output of this:
B4X:
Dim TimeZone As JavaObject
TimeZone = TimeZone.InitializeStatic("java.util.TimeZone").RunMethod("getDefault", Null)
Log(TimeZone)
B4X:
(ZoneInfo) sun.util.calendar.ZoneInfo[id="Africa/Cairo",offset=7200000,dstSavings=0,useDaylight=false,transitions=129,lastRule=null]
 
Upvote 0

teddybear

Well-Known Member
Licensed User
JDK needs to be upgraded. it works on jdk17, jdk21 also works
 
Last edited:
Upvote 0

hanyelmehy

Active Member
Licensed User
Longtime User
Are you sure that you are NOT calling DateTime.SetTimeZone somewhere? The offset should be 2 hours.
sorry ,when do test i forget to remove DateTime.SetTimeZone ,offset: value is 2
i think the issue that (useDaylight=false) ,when its actually on PC is true
 
Upvote 0
Top