Android Question b4a how to get Milliseconds? 2025-4-5 4:11:06:123

xiaoyao

Active Member
Licensed User
Longtime User
b4a how to get Milliseconds? 2025-4-5 4:11:06:123
or :
a=timer
msgbox("33"0
b=timer-a
get uesedtime with(Milliseconds) like 100ms or 1000.335 ms?
 
Solution
ok:
Sub GetTime() As String
    DateTime.DateFormat = "HH:mm:ss.SSS"
    Return DateTime.Date(DateTime.Now)
    'DateTime.DateFormat = "yyyy-MM-dd HH:mm:ss.SSS"
End Sub

xiaoyao

Active Member
Licensed User
Longtime User
ok:
Sub GetTime() As String
    DateTime.DateFormat = "HH:mm:ss.SSS"
    Return DateTime.Date(DateTime.Now)
    'DateTime.DateFormat = "yyyy-MM-dd HH:mm:ss.SSS"
End Sub
 
Upvote 0
Solution

emexes

Expert
Licensed User
Longtime User
how to get Milliseconds?

If you want to time how long a period is, then just use the number returned by DateTime.Now eg:

B4X:
Dim StartTime As Long = DateTime.Now
'lots of calculations or whatever
Dim EndTime As Long = DateTime.Now
Dim ElapsedTime As Long = EndTime - StartTime    'Int works for up to three weeks
Log("Those calculations took " & ElapsedTime & " milliseconds = " & _
    NumberFormat2(ElapsedTime / 1000, 1, 3, 3, False) & " seconds")

B4X:
Dim StartTime As Long = -1
Dim EndTime As Long = -1

Sub StartButton_Click
    StartTime = DateTime.Now
End Sub

Sub StopBotton_Click
    EndTime = DateTime.Now
    If StartTime > 0 Then
        Dim ElapsedTime As Long = EndTime - StartTime    'Int works for up to three weeks
        Log("Whatever you did, it took " & ElapsedTime & " milliseconds")
    End If
End Sub
 
Upvote 0
Top