Android Question GetHour, GetMinute, GetSecond

Tjitte Dijkstra

Member
Licensed User
Longtime User
Hi all,

In my program I need to pinpoint the moment the user started.
I tried it this way, but it doesnt work:

B4X:
Sub START_Click
Dim Begin As String
Dim H,M,S,StartTime As Int
    Begin = DateTime.Time(DateTime.Now) 'this is OK
        DateTime.GetHour(H) 'this returns 0
        DateTime.GetMinute(M) 'this returns 0
        DateTime.GetSecond(S) 'this returns 0
    StartTime = H*3600+M*60+S
display1.Text = Begin & " = 00.00"    'on display1 we see the real time of the moment
display2.Text = StartTime 'but on display2 we see only a zero
End Sub
 

Tjitte Dijkstra

Member
Licensed User
Longtime User
Thnx so far.
Begin (I DIMed it as a string) cannot be a double. That leads to the error "Invalid double".
But why does DateTime.Gethour(H) always resuklt in a 0?
 
Upvote 0

buras3

Active Member
Licensed User
Longtime User
I hope this will help you
B4X:
Sub ConvertToDate(sec As Long) As String
   Dim TempStr As String
   TempStr=NumberFormat(DateTime.GetDayOfMonth(sec),2,0)
   TempStr=TempStr & "/" & NumberFormat(DateTime.GetMonth(sec),2,0)
   TempStr=TempStr & "/" & DateTime.GetYear(sec)
   TempStr=TempStr & " " & NumberFormat(DateTime.GetHour(sec),2,0)
   TempStr=TempStr & ":" & NumberFormat(DateTime.GetMinute(sec),2,0)
   Return TempStr
End Sub
Sub ConvertToTimeFormat(sec As Long) As String
  Dim seconds, minutes ,hours As Long
   seconds = sec
  minutes = Floor(seconds / 60)
  seconds = seconds Mod 60
   hours=Floor(minutes / 60)
   minutes=minutes-hours*60
  Return NumberFormat(hours,2,0) & ":" & NumberFormat(minutes , 2,0) & ":" & NumberFormat(seconds, 2, 0)
End Sub
 
Upvote 0

Tjitte Dijkstra

Member
Licensed User
Longtime User
Thnx all,
After 25 years of experience with Turbo Pascal and Delphi, in which the GetTime works as you should expect, it surprises me that we need so much code in b4A for something simple.
Yet b4A is a great tool.
Maybe the book of Seagrave should have more examples?
TD
 
Upvote 0
Top