Android Question How can add minutes to "Now"?

Beja

Expert
Licensed User
Longtime User
Hi all,

I want to be able to add minutes (1 to 59) to the current device time.
Sorry but I couldn't find an example.
In vb6 it looks similar to: time_sum = now() + x/1440
Thank you in advance.

Edit example:
B4X:
Private Sub Command1_Click()
mm = Format(Now() + 20 / 1440, "HH:MM")
MsgBox mm
End Sub
 
Last edited:

Mahares

Expert
Licensed User
Longtime User
B4X:
Msgbox(NewTime(34),"")    'will display current time plus 34 minutes

Sub NewTime(mn As Double) As String
	Return DateTime.Time(DateTime.Now + mn * 60 * 1000)
End Sub
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Thanks Mahares so much, it worked like a charm.
Now another side issue.. how can I use the contents of a spinner which contains a number in
string format, to make it a number and add it to the time.
I tried val(spinner1) using Margret's string functions (checked the lib) but asked me to provide array!.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
You an have something like this:
B4X:
Dim sp As Spinner

sp.Initialize("sp")
sp.AddAll(Array As String("test1", "35", "17", "56"))
Activity.AddView(sp, 0, 600dip, 200dip, 50dip)

Sub sp_ItemClick (Position As Int, Value As Object)
    If IsNumber(Value) Then
			Msgbox(NewTime(Value),"")
		Else
			Msgbox("Sorry it is not a number.","")
		End If
End Sub

Sub NewTime(mn As Double) As String
	Return DateTime.Time(DateTime.Now + mn * 60 * 1000)
End Sub
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Thank you Mahares, my code was similar to this but your's is more compact.

mine was:
B4X:
Sub Button1_Click
If IsNumber(Spinner1.SelectedItem) Then
    SumTime.Text = NewTime(offset)
End If
End Sub
Sub NewTime(mn As Double) As String
Return DateTime.Time(DateTime.Now + mn * 60 * 1000)
End Sub

Sub Spinner1_ItemClick (Position As Int, Value As Object)
    offset = Spinner1.SelectedItem
End Sub

The variables were declared somewhere else
 
Upvote 0
Top