Hope someone can help as I'm going around in circles with dates, times and time zones.
I'd like to show the sum of durations of certain events in the form of hhh:mm
I have a list (DB) of event names and when they happened and the events could cross time zones, but I've stored the event time as a Tick without the time zone, i.e. when I stored the time I adjusted the time by adding DateTime.TicksPerHour * TimeZoneOffset
When I want to display the totals for each event I go through the list starting at the newest and subtracting the previous list value, this I think should give me the duration of the event in Ticks. I then add this to a total for each event. So I think I have the total number of Ticks (or time) for each event.
I just then need to display in hhh:mm.
I think I'm asking weather it is possible to subtract 2 Tick values to get the difference and then add these differences up? And then if this is OK how would I display the total in hhh:mm format?
'Format hhh:mm
Sub GetTime (Ticks As Long) As String
Dim hours As Int = Floor(Ticks / DateTime.TicksPerHour)
Dim minutes As Int = Floor((Ticks - hours * DateTime.TicksPerHour) / DateTime.TicksPerMinute)
Return hours & ":" & minutes
End Sub
I have another query, which I can't seem to work out what is going on. With the following code, the log shows
31 Dec 1969 16:00:00 I don't understand where the 16 hours comes from?
B4X:
For Each myKey In Map1.Keys
lSet = 0
Map1.Put(myKey,lSet)
Log (DateTime.Date(Map1.Get(myKey)) & " " & DateTime.time(Map1.Get(myKey)))
Next
I have another query, which I can't seem to work out what is going on. With the following code, the log shows
31 Dec 1969 16:00:00 I don't understand where the 16 hours comes from?
B4X:
For Each myKey In Map1.Keys
lSet = 0
Map1.Put(myKey,lSet)
Log (DateTime.Date(Map1.Get(myKey)) & " " & DateTime.time(Map1.Get(myKey)))
Next
Yes, think that must be it as I'm currently in California. So I guess it is actually being stored as zero but just change to 8 hours behind when I displays time.
Thanks