wimpie3 Well-Known Member Licensed User Longtime User Feb 21, 2014 #1 OK, let me first get this straight: B4A uses ticks to indicate a date/time. Ticks are the number of milliseconds passed since 1 Jan 1970. I have a mobile phone where the timezone is set to -9 hours. When I do this: Code: Copy Dim t As Long=0 Log(DateTime.GetDayOfMonth(t) & " / " & DateTime.GetMonth(t) & " / " & DateTime.GetYear(t)) I do NOT get 1/1/1970, but 31/12/1969. Probably because the timezone comes into play. I don't want that. I want 0 to be 1/1/1970. So I thought, lets set the timezone to 0: Code: Copy DateTime.SetTimeZone(0) Dim t As Long=0 Log(DateTime.GetDayOfMonth(t) & " / " & DateTime.GetMonth(t) & " / " & DateTime.GetYear(t)) Perfect. 0 ticks is now 1/1/1970. Exactly how I want it. However, some other date calculations seem to be incorrect now. Just look at the following example. The homescreen of my phone indicates we are the 21st of Feb 2014, 8:18. Code: Copy DateTime.SetTimeZone(0) Dim t As Long=DateTime.Now Log(DateTime.GetDayOfMonth(t) & " / " & DateTime.GetMonth(t) & " / " & DateTime.GetYear(t) & " " & DateTime.GetHour(t) & ":" & DateTime.GetMinute(t)) This code returns 21/2/2014 17:18, while I expected (and NEED) it to be 21/2/2014 8:18. So DateTime.SetTimeZone(0) is not enough to get rid of this whole timezone stuff. Is there something else I should do?
OK, let me first get this straight: B4A uses ticks to indicate a date/time. Ticks are the number of milliseconds passed since 1 Jan 1970. I have a mobile phone where the timezone is set to -9 hours. When I do this: Code: Copy Dim t As Long=0 Log(DateTime.GetDayOfMonth(t) & " / " & DateTime.GetMonth(t) & " / " & DateTime.GetYear(t)) I do NOT get 1/1/1970, but 31/12/1969. Probably because the timezone comes into play. I don't want that. I want 0 to be 1/1/1970. So I thought, lets set the timezone to 0: Code: Copy DateTime.SetTimeZone(0) Dim t As Long=0 Log(DateTime.GetDayOfMonth(t) & " / " & DateTime.GetMonth(t) & " / " & DateTime.GetYear(t)) Perfect. 0 ticks is now 1/1/1970. Exactly how I want it. However, some other date calculations seem to be incorrect now. Just look at the following example. The homescreen of my phone indicates we are the 21st of Feb 2014, 8:18. Code: Copy DateTime.SetTimeZone(0) Dim t As Long=DateTime.Now Log(DateTime.GetDayOfMonth(t) & " / " & DateTime.GetMonth(t) & " / " & DateTime.GetYear(t) & " " & DateTime.GetHour(t) & ":" & DateTime.GetMinute(t)) This code returns 21/2/2014 17:18, while I expected (and NEED) it to be 21/2/2014 8:18. So DateTime.SetTimeZone(0) is not enough to get rid of this whole timezone stuff. Is there something else I should do?
derez Expert Licensed User Longtime User Feb 21, 2014 #2 It says that it affects dates ! Try to add the DateTime.GetTimeZoneOffsetAt to t so you'll get the correct ticks. Upvote 0
It says that it affects dates ! Try to add the DateTime.GetTimeZoneOffsetAt to t so you'll get the correct ticks.
Erel B4X founder Staff member Licensed User Longtime User Feb 23, 2014 #3 In most cases you do not need to call these methods. What are you trying to calculate? Upvote 0